...

View Full Version : Text box disabling



rama
07-07-2002, 09:10 AM
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, 01: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?

rama
07-07-2002, 03:29 PM
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-08-2002, 12:15 AM
<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, 09: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 ...

:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum