[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Disabling form fields

Posted on 1998-10-06
4
Medium Priority
?
128 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

650 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