Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
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 24-Apr-13 0:47am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v3
Comments
prodipjsr at 24-Apr-13 6:41am
   
where i will write?? will u please write the code??
Jameel Moideen at 24-Apr-13 6:53am
   
when you want to disable the textboxes?
prodipjsr at 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..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
 
<input type="text" id="tbsecondnominee" />tbsecondnominee
 
<input type="text" id="tbsecondper" />tbsecondper
 
<input type="text" id="tbthitdnominee"/>tbthitdnominee
 
<input type="text" id="tbthirdper" />tbthirdper
  Permalink  
Comments
prodipjsr at 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 Moideen at 24-Apr-13 7:50am
   
did you want to disable all the textbox except tbfirstper?
z284122755 at 24-Apr-13 7:52am
   
sure
Jameel Moideen at 24-Apr-13 7:52am
   
i have updated the answer please try that
z284122755 at 24-Apr-13 8:02am
   
i have changed my code,please try that
Jameel Moideen at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

<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
 
<input type="text" id="tbsecondnominee" />tbsecondnominee
 
<input type="text" id="tbsecondper" />tbsecondper
 
<input type="text" id="tbthitdnominee"/>tbthitdnominee
 
<input type="text" id="tbthirdper" />tbthirdper
  Permalink  
Comments
prodipjsr at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100