...

View Full Version : Disable textbox on selecting a value in list



vorl
07-11-2005, 12:28 PM
hi
how would i go about disabling a text box when a particular value is selected in a list field??!! ive searched CF but could only find radio buttons and textboxes!!

any help appreciated!! :)

vorl

glenngv
07-11-2005, 12:44 PM
In this code, selecting "item 3" will disable the textbox and enable it otherwise.

Script:

function enableDisableText(objSel){
objSel.form.foo.disabled = (objSel.options[objSel.selectedIndex].value == "3") ? true:false;
}

HTML:

<select name="blah" onchange="enableDisableText(this)">
<option value="1">item 1</option>
<option value="2">item 2</option>
<option value="3">item 3</option>
</select>
<input type="text" name="foo" />

Kor
07-11-2005, 12:46 PM
<script type="text/javascript">
function dis(f,s){
f.elements['txt'].disabled=(s==2)?true:false;
}
</script>
....
...
<form>
<select onchange="dis(this.form,this.selectedIndex)">
<option value="">0</option>
<option value="">1</option>
<option value="">disable</option>
</select>
<input name="txt" type="text">
</form>

Kor
07-11-2005, 12:47 PM
..sorry, we have posted the same time... :D

vorl
07-11-2005, 01:08 PM
thanks guys for the quick response!!

It is just what i needed!! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum