Solved

Disabling form fields

Posted on 1998-10-06
4
121 Views
Last Modified: 2010-04-09
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.
0
Comment
Question by:lewin
4 Comments
 
LVL 1

Expert Comment

by:ptruman
Comment Utility
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.....
0
 
LVL 3

Accepted Solution

by:
zhongbing earned 200 total points
Comment Utility
the following javascript sample can do it.

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

var defaultvalue = "initial";

function check(formname){
//alert("xxx"+formname.radiobox[1].checked);
   if( formname.radiobox[1].checked) {
       formname.textbox.value = defaultvalue;
    }
}  


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

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

</body>
</HTML>
0
 
LVL 28

Expert Comment

by:sybe
Comment Utility
<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.
0
 
LVL 8

Expert Comment

by:jbirk
Comment Utility
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
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now