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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Non-selectable menu item 2

Status
Not open for further replies.
Aug 1, 2003
85
US
Is there a way to have a header in a drop down menu that isn't selectable?
I have a menu with "Select a Link" as the first option, First to give some direction and second to use as a spacer to keep the menu the right width.
I could do it in javascript but that's not foolproof.

Thanks
Dan
 
Could you get buy using a client-side form validation function to prevent the submission of forms if "Select a Link" is selected?
 
lets say i have a dropdown like below

Code:
<form name="myform" onsubmit="return validate_form(this)">
<select size="1" name="mydd">
<option value="0">-Select a link-</option>
<option value="1">Google</option>
<option value="2">Yahoo</option>
<option value="3">Msn</option>	
</select>
</form>

you can use client-side validation
Code:
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value=="0")
  {alert(alerttxt);return false}
else {return true}
}
}function validate_form(thisform)
{
with (thisform)
{
if (validate_required(myform,"Please select a link!")==false)
  {myform.focus();return false}
}
}
</script>

-DNG
 
Isn't it possible to turn off javascript on the client? If so that would "break" the page. I'm familiar with javascript and I'll use it if I have to but I was hoping for an alternative.

Thanks
Dan
 
Yes it is possible, you'd have to catch it also on the ASP side where you parsed the form input... it would just be a convience for the people that have JavaScript enabled.

 
Ok so the best thing to do at this stage is use both then. Could you help me out a little with the asp please?
Should I look up asp form validation?

Dan
 
You almost always want to do some degree of server side validation because, as you said, some people have no javascript and also because some users will enter stupid values.

Taking DNG's example HTML form above, the ASP validation might look something like this:[tt]
If (Len(Request.Form("mydd")) = 0) Then
Response.Write "Nothing was selected"
Response.End
End If

If (Request.Form("mydd") = "0") Then
Response.Write "You selected 'Select a link' ... very cute!"
Response.End
End If
[/tt]

... except you'd probably not use the cheeky responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top