Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A drop down queation?

Status
Not open for further replies.

markshen2004

Programmer
Jun 9, 2004
89
CA
I have a drop-down menu that like this.

<select name="select">
<option>Group A</option>
<option value="1">John</option>
<option value="2">Tom</option>
<option>Group B</option>
<option value="3">Jim</option>
<option value="4">Rob</option>
</select>

I do not like people to select Groupa,Group B option .they only used for description and do not have value to pass to next page.

Please give me a idea to protect them being selected.

Thanks for help
 
This works in newer browsers:
Code:
<select name="select">
  <optgroup label="Group A">
    <option value="1">John</option>
    <option value="2">Tom</option>
  </optgroup>
  <optgroup label="Group B">
    <option value="3">Jim</option>
    <option value="4">Rob</option>
  </optgroup>
</select>

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Well, you could write a JavaScript function to check the value of the select box. If the value is one of the options you'd like to avoid, you could either stop the form from submitting or display an error message.

Something like:

Code:
function validate() {
    var sel = document.the_form.the_select.value;
    if (sel == "") {
        alert("Not a valid selection.");
    }
}

And then, in the onchange() event of your select box, call the function.

Let me know if this helps.

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top