Br**************@gmail.com wrote:
Thanks Rob
I still dont get it!!!
do you have an example where the first option is normal
but second option disables textbox?
To disable an element that has a disabled attribute (button, input,
optgroup, option, select, textarea) set its value to true. To enable
it again, set disabled to false. The basic algorithm is:
if (condition) {
elementReference.disabled = true;
} else {
elementReference.disabled = false;
}
A shorthand method is to set the value of the disabled attribute to the
outcome of the condition statement:
elementReference.disabled = (condition);
That's effectively the same as the above 5 lines of code. The use of
"!!" in my earlier post was just to make sure that (condition) returned
true or false, it is probably not needed. Here's another example:
<form action="">
<div>
<select onchange="
if ( 1 == this.selectedIndex ) {
this.form.textA.disabled = true;
} else {
this.form.textA.disabled = false;
}
">
<option>Enable input
<option>Disable input
</select>
<input type="text" id="textA">
</div>
</form>
It's possible to get the two out of sync by reloading the page
(depending on the browser) as the input will probably become enabled
again but the selected option may not be reset. Hence my use of an
onload function to make sure they were synchronised.
--
Rob