View Full Version : Text box disabling
Hi,
i have 2 text boxes in my form.Value for both of them need not be entered by the user but if he enters value in one text box then the other one should automatically be disabled.
But if the user removes value in the textbox again both fields should be editable,similarly for the other textbox.
How do i achieve this using javascript
Thanks
Rama
hryan
07-07-2002, 12:29 PM
HI!
You can use a
funuction nnn(){
if(!this.form_name.txt_box1_name.value){
this.form_name.txt_box1_name.disabled=true;
this.form_name.txt_box2_name.disabled=true;
}
and to put into txtbox input tag this
onBlur="nnn()"
it executes a function nnn() when visitor leave your txtbox and the function checks IS FIRSTBOX empty. If YES, it disabled txtboxes.
OK?
Hi,
There was some problem with the if condition in the function and then i removed ! from it and it worked ,similarly i did for the other textbox it is working fine.
Thanks
Rama
adios
07-07-2002, 11:15 PM
<html>
<head>
<title>untitled</title>
</head>
<body>
<form>
<input name="t1" type="text"
onkeypress="t2.disabled=this.value"
onblur="t2.disabled=this.value"><br>
<input name="t2" type="text"
onkeypress="t1.disabled=this.value"
onblur="t1.disabled=this.value"><br>
</form>
</body>
</html>
hryan
07-11-2002, 08:30 AM
Hi !
if(!this.form_name.txt_box1_name.value) is equal to
if(this.form_name.txt_box1_name.value==NULL)
but you may use instead it conditions:
if(this.form_name.txt_box1_name.value!='') //if no empty string ...
or
if(this.form_name.txt_box1_name.value=='') //if empty string ...
:)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.