Click here to Skip to main content
14,699,608 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,

 please help me how to write the code


i have try the bellow code but when page load then all textboxes are enable..



<script type="text/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);
                }
            }
        }
    });
});
  </script>
Posted

Please put the below code inside the document.ready function.It will disabled the textbox when page load. Please make sure that you must implement the basic jQuery plugin. You can download latest jquery plugin from here http://jquery.com/download/[^]
$(document).ready(function()
{
//this code will disabled all the textboxex except the first one.
$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", "disabled"); 
});

Hope this helps
   
v3
Comments
prodipjsr 24-Apr-13 6:41am
   
where i will write?? will u please write the code??
Jameel VM 24-Apr-13 6:53am
   
when you want to disable the textboxes?
prodipjsr 24-Apr-13 7:47am
   
while page is loaded...only these 4 text boxes is disable::
tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper...
other text boxes is enable..
Hi,
I hava a qusetion about what you said.
when page load then all textboxes are enable
How can you input the value to tbfirstper?
here is my advise,please try this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    /*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,*/
	$(function(){
		$("input[type='text']:not(:eq(0))").attr("disabled",true);
		$("input[type='text']").blur(function(){
			var a = $("#tbfirstper").val();
			var b = $("#tbsecondper").val();
			//alert(a+b);

			if(parseInt(a)==100){
				$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
			}
			if(a<100 && a!="" && b==""){
				//alert(b);
				$("#tbsecondnominee,#tbsecondper").attr("disabled", false);
				$("#tbthitdnominee,#tbthirdper").attr("disabled", true);
			}
			if(b!="" && parseInt(a)+parseInt(b)<100){
				//alert(a+b);
				$("#tbthitdnominee,#tbthirdper").attr("disabled", false);
			}
		});

	});
</script>

<input type="text" id="tbfirstper" />tbfirstper<br />
<input type="text" id="tbsecondnominee" />tbsecondnominee<br />
<input type="text" id="tbsecondper" />tbsecondper<br />
<input type="text" id="tbthitdnominee"/>tbthitdnominee<br />
<input type="text" id="tbthirdper" />tbthirdper
   
Comments
prodipjsr 24-Apr-13 7:49am
   
sir, when i use this code then others texboxes in my page are disable. i want to disable these 4 textboxes while page load..
tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper..
not all the textboses,,,
Jameel VM 24-Apr-13 7:50am
   
did you want to disable all the textbox except tbfirstper?
z284122755 24-Apr-13 7:52am
   
sure
Jameel VM 24-Apr-13 7:52am
   
i have updated the answer please try that
z284122755 24-Apr-13 8:02am
   
i have changed my code,please try that
Jameel VM 24-Apr-13 11:45am
   
Please verify the id rendered in the browser. Because asp.net webform append masterpage id along with each control. So you need to change the id what actually rendered in the browser.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    /*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,*/
	$(function(){
		$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
		$("input[type='text']").blur(function(){
			var a = $("#tbfirstper").val();
			var b = $("#tbsecondper").val();
			//alert(a+b);

			if(parseInt(a)==100){
				$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
			}
			if(a<100 && a!="" && b==""){
				//alert(b);
				$("#tbsecondnominee,#tbsecondper").attr("disabled", false);
				$("#tbthitdnominee,#tbthirdper").attr("disabled", true);
			}
			if(b!="" && parseInt(a)+parseInt(b)<100){
				//alert(a+b);
				$("#tbthitdnominee,#tbthirdper").attr("disabled", false);
			}
		});

	});
</script>

<input type="text" id="tbfirstper" />tbfirstper<br />
<input type="text" id="tbsecondnominee" />tbsecondnominee<br />
<input type="text" id="tbsecondper" />tbsecondper<br />
<input type="text" id="tbthitdnominee"/>tbthitdnominee<br />
<input type="text" id="tbthirdper" />tbthirdper
   
Comments
prodipjsr 24-Apr-13 8:17am
   
sir,
when i apply this code then all text box are enable,not disable any text box....

for ur information i write all code which i hv been applied last 1 week..


<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Memberadd.aspx.cs" Inherits="New_NPS.Memberadd" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">

<asp:Content ID="Content4" ContentPlaceHolderID="MainContent" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">


<script type="text/javascript">
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode = 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
} else {
return true;
}
}
</script>

<script type="text/javascript">

$(document).ready(function () {
$('#<%=tbmemberdob.ClientID%>').datepicker({
dateFormat: 'mm-dd-yy',
changeMonth: true,
changeYear: true,
//yearRange: '-50:+0',
//yearRange: '-50y:c+nn',
//maxDate: '-1d',
//minDate: "-50Y",
//maxDate: "-18Y"
yearRange: '-58y:-19y'

});


});

</script>

<script type="text/javascript">
/*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,*/
$(function () {
$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
$("input[type='text']").blur(function () {
var a = $("#tbfirstper").val();
var b = $("#tbsecondper").val();
//alert(a+b);

if (parseInt(a) == 100) {
$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", true);
}
if (a < 100 && a != "" && b == "") {
//alert(b);
$("#tbsecondnominee,#tbsecondper").attr("disabled", false);
$("#tbthitdnominee,#tbthirdper").attr("disabled", true);
}
if (b != "" && parseInt(a) + parseInt(b) < 100) {
//alert(a+b);
$("#tbthitdnominee,#tbthirdper").attr("disabled", false);
}
});

});
</script>




<br />
<fieldset>
Member Information

Member ID  <asp:TextBox ID="tbmemberid" readonly="true" runat="server">
     Entry Date 
<asp:TextBox ID="tbentrydate" onfocus="blur()" STYLE="background-color:#5BF366"
runat="server" Height="25px" Width="181px"> 

<br />
<br />
Member First Name <asp:TextBox style="text-transform:uppercase" ID="tbmemfirstname" runat="server"> *
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbmemfirstname"
Display="Dynamic" ErrorMessage="should not be blank !!">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" FilterType="LowercaseLetters, UppercaseLetters" TargetControlID="tbmemfirstname" />
                 Member Middle Name <asp:TextBox ID="tbmemmeddlename" style="text-transform:uppercase" runat="server">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" runat="server" FilterType="LowercaseLetters, UppercaseLetters" TargetControlID="tbmemmeddlenam
prodipjsr 24-Apr-13 8:19am
   
<fieldset>
Nominee Information

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" value="0" 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" value="0" runat="server" Width="34px">
<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender11" runat="server" FilterType="Numbers" TargetControlID="tbthirdper" />
<br />
<br />
</fieldset>
z284122755 24-Apr-13 9:00am
   
are u add this src? don't forget you use jQuery not JS
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
if it is still dosen't work ,please press F12 and stick the warning

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