Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Any one please provide me the code for Jquery..


  • if tbfirstper==100 then tbsecondnominee,tbsecondper,tbthitdnominee,tbthirdper is not enable.
  • If tbfirstper <100;then tbsecondnominee,tbsecondper is enable,
  • if tbfirstper+tbsecondper<100, then tbthitdnominee,tbthirdper is enable,

I am new in jquery so please help me how to write the code
JavaScript
<script type="text/javascript">
    $(document).ready(function () {
        $("#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").blur(function () {
            var v1 = $("#tbfirstper").val(),
          v2 = $("#tbsecondper").val();
            if (!isNaN(v1)) {
                if (parseInt(v1, 10) == 100) {
                    $("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);

                }
                else if (parseInt(v1, 10) < 100) {
                    $("#tbthitdnominee,#tbthirdper").attr("disabled", true);
                    $("#tbsecondnominee,#tbsecondper").attr("disabled", false);
                }
                if (!isNaN(v2)) {
                    if ((parseInt(v2, 10) + parseInt(v1, 10)) == 100) {
                        $("#tbthitdnominee,#tbthirdper").attr("disabled", true);
                    }
                    else if ((parseInt(v2, 10) + parseInt(v1, 10)) < 100) {
                        $("#tbthitdnominee,#tbthirdper").attr("disabled", false);
                    }
                }
            }
        });
    });
</script>

but this is now work..when i put 100 in tbfirstper text box then others texboxes is not disable..
Posted
Updated 16-Feb-17 22:02pm
v3
Comments
F-ES Sitecore 17-Feb-17 4:32am    
View the source of the page, do you have elements with ids like "tbfirstper" etc? That might be the ID you give the control server-side, but for client-side (where jquery runs) the ID might be changed, especially if you use master pages or the controls are inside containers. If the js is on the same page as the controls then do things like this instead

v2 = $("#<%=tbsecondper.ClientID%>").val();

Hello,

You don't have code to reset the disable attribute once value of field tbfirstper is set to 100. Try adding following line at the start of blur function.
JavaScript
$("#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", false);

Your javascript function should look similar to one shown below.
JavaScript
$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
$(document).ready(function () {
    // if tbfirstper==100 then tbsecondnominee,tbsecondper,tbthitdnominee,tbthirdper is not enable.
    // If tbfirstper <100;then tbsecondnominee,tbsecondper is enable,
    // if tbfirstper+tbsecondper<100, then tbthitdnominee,tbthirdper is enable
    $("#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").blur(function () {
        $("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
        var v1 = $("#tbfirstper").val(),
        v2 = $("#tbsecondper").val();
        if (!isNaN(v1)) {
            if (parseInt(v1, 10) == 100) {
                $("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
            }
            else if (parseInt(v1, 10) < 100) {
                $("#tbthitdnominee,#tbthirdper").attr("disabled", true);
                $("#tbsecondnominee,#tbsecondper").attr("disabled", false);
            }
            if (!isNaN(v2)) {
                if ((parseInt(v2, 10) + parseInt(v1, 10)) == 100) {
                    $("#tbthitdnominee,#tbthirdper").attr("disabled", true);
                }
                else if ((parseInt(v2, 10) + parseInt(v1, 10)) < 100) {
                    $("#tbthitdnominee,#tbthirdper").attr("disabled", false);
                }
            }
        }
    });
});

Regards,
 
Share this answer
 
v3
Comments
prodipjsr 20-Apr-13 8:01am    
means what?? sir i am not clear of ur views..
Prasad Khandekar 20-Apr-13 15:24pm    
If you add the above mentioned statement as the first line your blur function then it will reset all the text boxes and enable them. The subsequent code will then disable the required textboxes.
prodipjsr 21-Apr-13 3:23am    
sir, i hv change the code (true to false) but still no effect ..
Prasad Khandekar 21-Apr-13 13:26pm    
I have updated the solution please check it.
prodipjsr 22-Apr-13 0:59am    
Hello sir, No update:; i cant understand where is the problem, i hv used the following control for the textboxes.. is there any problem??/

<fieldset>
Nominee Information
<br />
First Nominee Name <asp:TextBox ID="tbfirstnominee" style="text-transform:uppercase" runat="server">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender8" runat="server" FilterType="LowercaseLetters,UppercaseLetters" TargetControlID="tbfirstnominee" />
  Percentage <asp:TextBox ID="tbfirstper" MaxLength="3" runat="server" Width="35px">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender9" runat="server" FilterType="Numbers" TargetControlID="tbfirstper" />
<br />
<br />
Second Mominee Name <asp:TextBox ID="tbsecondnominee" style="text-transform:uppercase" runat="server">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender12" runat="server" FilterType="LowercaseLetters,UppercaseLetters" TargetControlID="tbsecondnominee" />
  Percentage <asp:TextBox ID="tbsecondper" MaxLength="3" runat="server" Width="34px">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender10" runat="server" FilterType="Numbers" TargetControlID="tbsecondper" />
<br />
<br />
Third Mominee Name <asp:TextBox ID="tbthitdnominee" style="text-transform:uppercase" runat="server">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender13" runat="server" FilterType="LowercaseLetters,UppercaseLetters" TargetControlID="tbthitdnominee" />
  Percentage <asp:TextBox ID="tbthirdper" MaxLength="3" runat="server" Width="34px">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender11" runat="server" FilterType="Numbers" TargetControlID="tbthirdper" />
<br />
<br />
</fieldset>
I didn't take the time to test it, just a quick rewrite from how I interpreted it.

$(document).ready(function () {
        
    $("#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").blur(function () {
        
        var txt_v1 = $("#tbfirstper").val();
        var txt_v2 = $("#tbsecondper").val();
        var v1 = parseInt(txt_v1);
        var v2 = parseInt(txt_v2);
                
        if (false == isNaN(v2)) {
            if (v1 == 100) {
                $("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", "disabled");
 
            }
            else if (v1 < 100) {
                $("#tbthitdnominee,#tbthirdper").removeAttr("disabled");
                $("#tbsecondnominee,#tbsecondper").removeattr("disabled");
            }
        }
            
        if ((v1 + v2) == 100) {
                $("#tbthitdnominee,#tbthirdper").removeAttr("disabled");
            }
            else if ((v1 + v2) < 100) {
                $("#tbthitdnominee,#tbthirdper").removeAttr("disabled");
            }
        }
                
    });

});
 
Share this answer
 
Comments
prodipjsr 22-Apr-13 1:00am    
sir, There is no update..
prodipjsr 22-Apr-13 6:00am    
any one please help me!!!!
jkirkerx 22-Apr-13 13:01pm    
You need to tell me what part is not working. Is the Blur statement not working, and the script is not running?

Are the textboxes not being disabled?
prodipjsr 23-Apr-13 4:21am    
The textboxes not being disabled.
jkirkerx 23-Apr-13 12:31pm    
$(#te4xtbox).attr("disabled", "disabled")

will disable the textbox in jquery

Sounds like the function is not running, you should test it using alert("I Fired") to make sure the code is firing under the blur condition.

Make sure you have jQuery loaded by making a reference to it.
<script src="jquery.js"></script>

http://learn.jquery.com/about-jquery/how-jquery-works/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900