Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

disable other textfield as one textfield entered

 
aman hindustani
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends...

In my module ..i am creating three text fields..as soon as we enter one text filed..the other two fields should be disabled..i have written a code..but some time showing error..as 1st field is enter ..2nd is disabled but third is becoing enable..some times working perfect...

please help me out what is the the errror...thanks in advance




<html>
<head> This is Enable and Disable Textfiled programme</head>
<body bgcolor=honeydew>
<form name="EnableDisable" method="post" >


<table>
<tr><td>Enter only one Name : </td>
<td><Input type=textfield name=TextField11 value="" onchange="call1();"></td>
<td><Input type=textfield name=TextField12 value="" onchange="call1();"></td>
<td><Input type=textfield name=TextField13 value="" onchange="call1();"></td>
</tr></table>

<script type="text/javascript" language="JavaScript">
function call1(){

var textField11 = document.EnableDisable.TextField11.value;
var textField12 = document.EnableDisable.TextField12.value;
var textField13 = document.EnableDisable.TextField13.value;

alert(" 1 "+textField11);
alert(" 2 " +textField12);
alert(" 3 "+textField13);

if(textField11 != null )
{
alert(" 4 "+textField11);
document.EnableDisable.TextField11.disabled = false;
document.EnableDisable.TextField12.disabled = true;
document.EnableDisable.TextField13.disabled = true;

}

if(textField12 !=null )
{
alert(" 5 "+textField12);
document.EnableDisable.TextField11.disabled = true;
document.EnableDisable.TextField12.disabled = false;
document.EnableDisable.TextField13.disabled = true;
}



if(textField13 != null )
{
alert(" 6 "+textField13);
document.EnableDisable.TextField11.disabled = true;
document.EnableDisable.TextField12.disabled = true;
document.EnableDisable.TextField13.disabled = false;
}


}

</script>
</form>
</html>
 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this out ...


if(textField11 != null )
{
alert(" 4 "+textField11);
document.EnableDisable.TextField11.disabled = false;
document.EnableDisable.TextField12.value ="";
document.EnableDisable.TextField13.value = "";
document.EnableDisable.TextField12.disabled = true;
document.EnableDisable.TextField13.disabled = true;

}

and while checking for null also check for ""
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post HTML and Javascript questions in the appropriate forum. Moved to the HTML forum.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably want to look at the lenght property instead of null.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic