my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes disable other textfield as one textfield entered Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "disable other textfield as one textfield entered" Watch "disable other textfield as one textfield entered" New topic

disable other textfield as one textfield entered

aman hindustani
Ranch Hand

Joined: Jun 15, 2006
Posts: 57
hello friends...

In my module ..i am creating three text soon as we enter one text filed..the other two fields should be disabled..i have written a code..but some time showing 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

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

<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>

<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;


ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
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

Joined: Jan 10, 2002
Posts: 60798

Please post HTML and Javascript questions in the appropriate forum. Moved to the HTML forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15376
You probably want to look at the lenght property instead of null.

I agree. Here's the link:
subject: disable other textfield as one textfield entered
Similar Threads
How can I enable and disable a single row of textboxes in a table using javascript?
enable and disable a text field
spaces while populating using s:iterator
toggle checkbox group when the max limit is reached
help needed..sigh...