473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to enable/disable textbox in JavaScript

35 New Member
Javascript help

hi guyz i have a question how can i disable all my textbox in my form if my verification code is not correct? e.g(my verification code is " ng075 " if ng075 is not put in my textbox then the other textbox must be disable..all suggestion are well appreciated..th anks guys in advance i'm really having a hard time right now:(
Apr 19 '12 #1
6 17325
SeanPD
4 New Member
I will offer a JQuery script as the Javascript is a bit long and it is SO simple in JQuery.

First lets include the JQuery Library from Google.
Expand|Select|Wrap|Line Numbers
  1.  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
Next lets assume you verification code input box has an attribute ID="VerifyCD".

We add a functiuon to fire OnBlur (when you leave the verification text box) that will check the code and enable/disable all other input text boxes:

Expand|Select|Wrap|Line Numbers
  1. $('#VerifyCD).blur(function() {
  2.     if ($('#VerifyCD).val() <> "ng075" ) {
  3.         $('input:text').attr('disabled', true);
  4.         $('#VerifyCD).removeAttr('disabled');
  5.     } else {
  6.         $('input:text').removeAttr('disabled');
  7.     }
  8.  
  9. });
How it works:
$('#VerifyCD).b lur(function() just means when the user leaves the VerifyCD textbox, run this function.

if ($('#VerifyCD). val() <> "ng075" ) just says if the value they entered is NOT your verify code then
$('input:text') take all text input boxes
.attr('disabled ', true); and set their disable attribute to true
Expand|Select|Wrap|Line Numbers
  1. $('#VerifyCD).removeAttr('disabled');
alweays re-enable our VerifyCD text box

Expand|Select|Wrap|Line Numbers
  1. } else {
$('input:text') take all text input boxes
.removeAttr('di sabled'); and remove their disable attr
}

I know it is not quite what you asked for, but I hope that helps.

Sean
Apr 19 '12 #2
SeanPD
4 New Member
YIKES ...
Everywhere I said $('#VerifyCD)
it should be: $('#VerifyCD')
sorry, I missed the closing quote.
Apr 19 '12 #3
ehpratah
35 New Member
thanks Sean for the rply i'll be in touch with you i'll try it first if it will work..thanks again
Apr 20 '12 #4
Bharat383
93 New Member
Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript">
  3.     function kk1()
  4.     {
  5.         document.getElementById("txt1").disabled  = true;
  6.     }
  7.     function kk2()
  8.     {
  9.         document.getElementById("txt1").disabled  = false;
  10.  
  11.     }
  12. </script>
  13. </head>
  14. <body>
  15.     <input type="button" name="btn1" id="btn1" onclick="kk1()"  value="Disable" />
  16.     <input type="button" name="btn2" id="btn2" onclick="kk2()" value="Enable" />
  17.     <br />
  18.     <input type="text" name="txt1" id="txt1" value="" />
  19. <body>
Apr 21 '12 #5
SHANIKA
1 New Member
First Create html page with 2 button and 1 textbox.this tutorial learn about the Text box disable using javascript.if Yes Button is click, the TextBox enabled and if No Button is click the TextBox disabled.

this article I will Learn with an example, How to Enable or Disable TextBox on Button Click using JavaScript. if Yes Button is click, the TextBox enabled and if No Button is click the TextBox disabled.
Feb 18 '20 #6
SioSio
272 Contributor
I wrote the code as requested by ehpratah.
Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript">
  3. function changeDisabled(){
  4.   var obj_1 = document.getElementById("txt1");
  5.   var obj_2 = document.getElementById("txt2");
  6.   var obj_3 = document.getElementById("txt3");
  7.   if(obj_1.value == "ng075"){
  8.     obj_2.disabled = false;
  9.     obj_3.disabled = false;
  10.   }else{
  11.     obj_2.disabled = true;
  12.     obj_3.disabled = true;
  13.   }
  14. }
  15. </script>
  16. </head>
  17. <body>
  18.   <input type="text" value="" id="txt1" />
  19.   <input type="text" value="" id="txt2" disabled />
  20.   <input type="text" value="" id="txt3" disabled />
  21.   <input type="button" value="Button" id ="btn1" onclick="changeDisabled();" />
  22. </body>
Feb 18 '20 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
9732
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field in my asp form i use a checkbox and fot he other field i use a normal text box. if the yes/no field is checked then the other field is enabled otherwise it has to be disabled.Here's what i've done so far: Do While Not ObjRS.EOF <td><input...
2
6452
by: HolaGoogle | last post by:
Can you please tell me the right way to do this?? it's realy important! thanks in advance... Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field in my asp form i use a checkbox and fot he other field i use a normal text box. if the yes/no field is checked then the other field is enabled...
3
9200
by: Bob Bedford | last post by:
I've this code: function checkdate(FormSubmit){ alert(document.getElementById('Mois').value); if(eval(document.getElementById('Mois'))>0 && eval(document.getElementById('Annee'))>0){ document.forms.getElementByID('SELECTCONSTRUCTOR').disabled = false; //can't reach the control here } else
3
15948
by: Alphonse Giambrone | last post by:
I am trying to enable/disable a requiredfieldvalidator on the client side and am generating an error. I had found some documentation on validation which states that I should be able to enable/disable validators on the client side. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspplusvalid.asp According to it and the little other info I was able to find, the way to accomplish what I want it to call...
1
4243
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES is selected - enable a field to use the M$ Datepicker. Using the code below works for most of our fields, however the problem is that when the field is re-enabled - it remembers the original date or data prior to it being disabled - despite the...
3
3081
by: MJB | last post by:
I am using the embedded ActiveX IE WebBrowser component in my C# application. I want to be able to Enable/Disable javascripting programmatically. I was wondering if there was a way to achieve this? I was hoping maybe there was a registery entry I could modify directly. Any help will be appreciated. Thanks, Matt
6
6942
by: M O J O | last post by:
Hi, I have a webform with a textbox and a button. When the textbox is empty (=""), I want the button to be disabled. When the user enters text in the textbox, the button must be enabled. Is this possible? (please if possible, show me the code)
2
2375
by: Water Cooler v2 | last post by:
How do you enable/disable JavaScript in Internet Explorer v6?
6
20851
by: kfank | last post by:
I have a multi-line TextBox with a vertical scrollbar that logs data from a realtime process. Currently, whenever a new line is added the textbox scrolls to the bottom so you can see the last entry. I would like to suspend this behavior if the user has used the scrollbar to view somewhere else in the textbox. Is there a preferred way to do this? There does not appear to be any mouse events for the scroll bar - they only fire over the client...
3
3191
by: sanndeb | last post by:
I want to enable/disable controls of a asp.net page against a logged in user's permission. say 'admin' & 'hr' can change user's birth date text-box in a page but others will see the text-box as disabled. so i wrote a function like this public enum UserRoles { GroupLead = 0x2, WebAdmin = 0x4, Developers = 0x8, Hr = 0x10,
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.