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

Validation in a jump menu 2

Status
Not open for further replies.

MikeDee

Programmer
Aug 2, 2001
19
0
0
GB
Hi everybody, I'm trying to have validation in a jump menu.

So when you submit without selecting an option
alert("please select an option in the menu");

when an option has been selected

alert("Its good");}

Below is what is trying to do that but doesn't work.


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script language=&quot;JavaScript&quot;>
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+&quot;.location='&quot;+selObj.options[selObj.selectedIndex].value+&quot;'&quot;);
if (restore) selObj.selectedIndex=0;
}

function feeed()
{
if (document.theform.menu1.value == &quot;&quot;)
{alert(&quot;please select an option in the menu&quot;);}
else
{alert(&quot;Its good&quot;);}
}

//-->
</script>


</head>

<body bgcolor=&quot;#FFFFFF&quot;>
<form name=&quot;theform&quot; method=&quot;post&quot; action=&quot;&quot; onchange=&quot;feeed&quot;;>
<p>
<select name=&quot;menu1&quot; onChange=&quot;MM_jumpMenu('parent',this,0)&quot;>
<option>please select</option>
<option value=&quot;opt1.htm&quot;>opt 1</option>
<option value=&quot;opt2.htm&quot;>opt 2</option>
<option value=&quot;opt3.htm&quot;>opt 3</option>
</select>
</p>
<p><input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</p></form>
<p>&nbsp; </p>
</body>
</html>
 
Try this,

[tt]<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script language=&quot;JavaScript&quot;>
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+&quot;.location='&quot;+selObj.options[selObj.selectedIndex].value+&quot;'&quot;);
if (restore) selObj.selectedIndex=0;
}

function feeed()
{
if (document.theform.menu1.options.selectedIndex==0)
{alert(&quot;please select an option in the menu&quot;);}
else
{alert(&quot;Its good&quot;);}
}
//-->
</script>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>
<form name=&quot;theform&quot; method=&quot;post&quot; action=&quot;javascript:feeed()&quot; onchange=&quot;feeed&quot;;>
<p>
<select name=&quot;menu1&quot; onChange=&quot;MM_jumpMenu('parent',this,0)&quot;>
<option>please select</option>
<option value=&quot;opt1.htm&quot;>opt 1</option>
<option value=&quot;opt2.htm&quot;>opt 2</option>
<option value=&quot;opt3.htm&quot;>opt 3</option>
</select>
</p>
<p><input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</p></form>
<p> </p>
</body>
</html>[/tt]

Red shows the modifications i have made. DeltaFlyer
The Only Programmer To Crash With Style. LOL
 
hie
function feeed()
{
if (document.theform.menu1.value == &quot;&quot;)
{alert(&quot;please select an option in the menu&quot;); return false}
else
{alert(&quot;Its good&quot;); return true}
}

~~~~~~~~~

<form name=&quot;theform&quot; method=&quot;post&quot; action=&quot;&quot; onsubmit=&quot;return feeed()&quot;;>

this will do validation onsubmit.. regards, vic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top