Solved

Disabling form fields

Posted on 1998-10-06
4
124 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

821 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