Solved

Disabling form fields

Posted on 1998-10-06
4
123 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
ID: 1838421
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
ID: 1838422
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
ID: 1838423
<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
ID: 1838424
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

809 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