• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 132
  • Last Modified:

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.
1 Solution
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.....
the following javascript sample can do it.

<title> test page </title>
<script language="JavaScript">

var defaultvalue = "initial";

function check(formname){
   if( formname.radiobox[1].checked) {
       formname.textbox.value = defaultvalue;

<script language="JavaScript">
// alert("appName = " + navigator.appName);
<form name="test name" method="get">
 <input type="radio" name="radiobox" checked > enable

 <input type="radio" name="radiobox" > disable
 <input type="text" name="textbox" onChange="check(this.form);">
 <input type="text" name="textbox2" >

var fieldenabled = false;
function WriteField(field) {
  if (!fieldenabled) {
function EnableField() {
   this.fieldenabled = true;

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

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now