Forum Moderators: open

Message Too Old, No Replies

Disable Text Field If Selected in Dropdown

         

syktek

7:58 pm on Dec 19, 2006 (gmt 0)

10+ Year Member



I would like to disable a text field if something specific is selected in a drop down.

<form action="" method="POST" name="form1">
<select name="state">
<option value="#">NY</option>
<option value="#">NJ</option>
<option value="#">CT</option>
<option value="#" onselect="javascript:document.form1.notus.disabled=false">Other</option>
</select>
<input type="text" maxlength="50" size="20" name="notus" disabled>
</form>

If "Other" is selected from the drop down I would like the text field to be enabled, if it changes I would like the text field to be disabled. Kind of lost :\

-Stephen

syktek

8:22 pm on Dec 19, 2006 (gmt 0)

10+ Year Member



i have also tried this with no luck:

<form action="" method="POST" name="form1">
<select name="state">
<option value="#">NY</option>
<option value="#">NJ</option>
<option value="#">CT</option>
<option value="#" onselect="document.getElementById('notus').disabled=false">Other</option>
</select>
<input type="text" maxlength="50" size="20" id="notus" name="notus" disabled>
</form>

syktek

9:00 pm on Dec 19, 2006 (gmt 0)

10+ Year Member



came up with this and it seems to work, thought i could take the easy way out before:

function findselected(){
var state = document.getElementById('state');
var notus = document.getElementById('notus');
(state.value == "Other")? notus.disabled=false : notus.disabled=true
}
</script>

<form action="" method="POST" name="form1">
<select name="state" id="state" onChange="findselected()">
<option value="NY">NY</option>
<option value="NJ">NJ</option>
<option value="CT">CT</option>
<option value="Other">Other</option>
</select>
<input type="text" maxlength="50" size="20" id="notus" name="notus" disabled>
</form>