Link to home
Start Free TrialLog in
Avatar of lewin
lewin

asked on

Disabling form fields

Is it possible to have a radio button in a form and when a certain option is chosen a text box become enabled?  I have tried using the disabled option but Netscape does not seem to support this.  Also I don't know how you would change the disabled attribute dynamically.  With JavaScript??

Thanks in advance.
Avatar of ptruman
ptruman

Unless you use a Javascript controlled Style Sheet,
the only way to do it is to constantly monitor your form's
radiobutton status and depending on the state, change the value
of the text field to ""
You can add on onEntry/onChange bit of script to the text
field to do this as well.....
ASKER CERTIFIED SOLUTION
Avatar of zhongbing
zhongbing

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sybe
<script>
var fieldenabled = false;
function WriteField(field) {
  if (!fieldenabled) {
     field.blur();
  }
}
function EnableField() {
   this.fieldenabled = true;
}
</script>

<form>
<input type="radio" name="myRadio" onClick="EnableField()">
<input type="text" onFocus="WriteField(this)">
</form>

I checked it is NS4 and NS3, but for unknown reason it won't work in NS3. I'll look at it more closely.
I think sybe's method is better, but using onClick may be causing a problem.  I suggest using onFocus instead.  Also this will work when they get to the field by tabbing whereas your method will not work for that.
Also you might want to put a:
      formname.textbox.value = defaultvalue;
immediately after the blur statement just for good mesure.
-Josh