Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to disable a form field?

Posted on 2006-05-15
11
Medium Priority
?
190 Views
Last Modified: 2013-12-24
I need to disable a form field when "EV" is selected from a drop-down list.
The drop-down field already has an "onClick" event assigned to it.

Any ideas how to do this?
0
Comment
Question by:g118481
  • 6
  • 4
11 Comments
 
LVL 35

Expert Comment

by:mrichmon
ID: 16684604
You can assign multiple events to the onClick or onCHange (which is usually better for a drop-down).

Basically you just use javascript to change the status to disabled.

http://www.quirksmode.org/js/disabled.html
0
 
LVL 1

Author Comment

by:g118481
ID: 16685682
This is only part of what I need.

If "EV" from the drop down list is selected in the form, then the other drop down list "reasonout" needs to be disabled.
How can I do that?

Increasing points.
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16686314
if(document.formname.dropdownname.options[document.formname.dropdownname.selectedIndex].value == "EV")
{   code to disable goes here   }
0
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.

 
LVL 1

Author Comment

by:g118481
ID: 16686594
Mitch,

Could you be more specific of how to setup the code, where in relation to the form it goes, and how it works?
So, if this were my form where would I insert the code?

<form>
<select name=event>
<option value=EV>EV</option>
<option value=AT>AT</option>
</select>

<select name=reasonout>
<option value=EV>EV</option>
<option value=AT>AT</option>
</select>

Just trying to ask the correct question in order to understand your suggestion more fully.
Thanks
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16686617
Who is mitch?  Do you have this question posted somwhere else as well?
0
 
LVL 1

Author Comment

by:g118481
ID: 16686833
sorry, i thought m stood for Mitch.
0
 
LVL 1

Author Comment

by:g118481
ID: 16689578
MRICHMON,

Sorry for calling you Mitch, it was an honest mistake.  

Could you be more specific of how to setup the code, where in relation to the form it goes, and how it works?
So, if this were my form where would I insert the code?

<form>
<select name=event>
<option value=EV>EV</option>
<option value=AT>AT</option>
</select>

<select name=reasonout>
<option value=EV>EV</option>
<option value=AT>AT</option>
</select>

Just trying to ask the correct question in order to understand your suggestion more fully.
Thanks
0
 
LVL 25

Assisted Solution

by:dgrafx
dgrafx earned 200 total points
ID: 16689725
<form>
<select name="event" onchange="if(this.value=='EV') this.form.reasonout.disabled=true ; else this.form.reasonout.disabled=false">
<option value="AT">AT</option>
<option value="EV">EV</option>
</select>

<select name="reasonout">
<option value="EV">EV</option>
<option value="AT">AT</option>
</select>
</form>

notice i changed the order of AT & EV in first select box - other wise would need an onload event
0
 
LVL 1

Author Comment

by:g118481
ID: 16691373
Is there a way to have two "onchange" events for the "event" drop-down select?

As I mentioned in my initial posting, this event drop-down already has an onchange event that populates a third drop-down list.

Any suggestions?
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 1000 total points
ID: 16691411
In the head of the page you need:

<script type="text/javascript">
function TestForEV()
{
  if(document.myform.event.options[document.myform.event.selectedIndex].value == "EV")
   {   document.myform.reasonout.disabled = true;   }
  else
   {   document.myform.reasonout.disabled = false;  }
}
</script>


<form name="myform>
<select name="event" onchange="FIrstfunction();TestForEV();">
<option value="AT">AT</option>
<option value="EV">EV</option>
</select>

<select name="reasonout">
<option value="EV">EV</option>
<option value="AT">AT</option>
</select>
</form>
0
 
LVL 1

Author Comment

by:g118481
ID: 16691486
This works perfect.
Thanks.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
What You Need to Know when Searching for a Webhost Provider
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

578 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