It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Validate Menu lists when none selected

Validate Menu lists when none selected

Postby ammweb on Mon Jun 23, 2008 8:50 pm

How would you validate a page that had several drop down menus. When the submit button is submitted, and NO selection has been made?

See code below:
<html>
<head>

</head>
<body>

<table width="100%" height="500px" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="600px" valign="top" bgcolor="#F5F0DD"><table width="100%" height="452" border="1" bgcolor="#BFD5EA">
<form action="remcardqueue.asp" method="post">
<input name="subject" type="hidden" value="AMM | Remembrance Card Package Order" />
<input name="MAILCODE" type="hidden" value="XXXX" />
<tr>
<td height="66" colspan="3"><div align="center"><font color="#006633" size="5">Remembrance Card Package Selection</font></div></td>
</tr>
<tr>
<td width="22%" height="66"><div align="center"><img src="images/cards/1111.jpg" alt="Association Standard Remembrance Card Package" border="0"><br />
<span class="smallfont">Click to view details</span></div></td>
<td width="58%" class="surveysmall"><p><b><font color="#006633">Association Standard Remembrance Card Package</font><font color="#006600">(One of each of the cards shown here)<br />
</font></b><span class="surveyfont"> X1111</span> </p> </td>
<td width="20%" class="surveysmall"><div align="right">

<select name="X1111" id="X1111">
<option value="0">0</option>
<option value="1">1</option>
</select></div></td>
</tr>
<tr>
<td height="58"><div align="center"><a href="http://www.amm.org/cards/cdpkg/d011.asp" target="_NewWin"><img src="images/cards/D011.jpg" alt="Baby Remembrance" width="30" height="45" border="0"><br />
<span class="smallfont">Click to view details</span></a></div></td>
<td class="surveysmall"><p><b><font color="#006633">Baby Remembrance Folder</font></b><br />
<span class="surveyfont">D011</span> </td>
<td class="surveysmall"><div align="right">

<select name="D011" id="D011">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></div></td>
</tr>
<tr>
<td><div align="center"><a href="http://www.amm.org/cards/cdpkg/dfp006.asp" target="_NewWin"><img src="images/cards/dfp006.jpg" alt="Family Prayer" width="32" height="45" border="0" /></a><br />
<a href="http://www.amm.org/cards/cdpkg/dfp006.asp" target="_NewWin"><span class="smallfont">Click to view details</span></a></div></td>
<td><p><span class="surveysmall"><b><font color="#006633">Family Prayer Folder
</font></b><br />
</span><span class="surveyfont">DFP006</span>
</td>
<td><div align="right">

<select name="DFP006" id="DFP006">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></div></td>
</tr>
<tr>
<td><div align="center"><a href="http://www.amm.org/cards/cdpkg/dh215.asp" target="_NewWin"><img src="images/cards/DH215.jpg" alt="Healing Remembrance" width="30" height="41" border="0" /></a><br />
<a href="http://www.amm.org/cards/cdpkg/dh215.asp" target="_NewWin"><span class="smallfont">Click to view details</span></a></div></td>
<td><span class="surveysmall"><b><font color="#006633">Healing Folder</font></b><br />
</span><span class="surveyfont">DH215</span> </td>
<td><div align="right">

<select name="DH215" id="DH215">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></div></td>
</tr>
<tr>
<td><div align="center"><a href="http://www.amm.org/cards/cdpkg/dh005.asp" target="_NewWin"><img src="images/cards/dh005.jpg" alt="Healing Remembrance" width="31" height="45" border="0" /></a><br />
<a href="http://www.amm.org/cards/cdpkg/dh005.asp" target="_NewWin"><span class="smallfont">Click to view details</span></a></div></td>
<td><span class="surveysmall"><b><font color="#006633">Healing Folder</font></b><br />
</span><span class="surveyfont">DH005</span> </td>
<td><div align="right">

<select name="DH005" id="DH005">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></div></td>
</tr>
<tr>
<td><div align="center"><a href="http://www.amm.org/cards/cdpkg/dh106.asp" target="_NewWin"><img src="images/cards/dh106.jpg" alt="Healing Remembrance" width="30" height="42" border="0" /></a><br />
<a href="http://www.amm.org/cards/cdpkg/dh106.asp" target="_NewWin"><span class="smallfont">Click to view details</span></a></div></td>
<td><span class="surveysmall"><b><font color="#006633">Healing Folder</font></b><br />
</span><span class="surveyfont">DH106</span> </td>
<td><div align="right">

<select name="DH106" id="DH106">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></div></td>
</tr>
<tr>
<td><div align="center"><a href="http://www.amm.org/cards/cdpkg/d3106.asp" target="_NewWin"><img src="images/cards/d3106.jpg" alt="Memorial Remembrance" width="32" height="45" border="0" /></a><br />
<a href="http://www.amm.org/cards/cdpkg/d3106.asp" target="_NewWin"><span class="smallfont">Click to view details</span></a></div></td>
<td><span class="surveysmall"><b><font color="#006633">Memorial Remembrance Folder</font></b><br />
</span><span class="surveyfont">D3106</span> </td>
<td><div align="right">

<select name="D3106" id="D3106">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select></div></td>
</tr>
<tr bgcolor="f5f0dd">
<td colspan="4"><div align="center">
<p>&nbsp; </p>

<input type="submit" name="button" id="button" value="Create Your Card Package"/>
</div></td>
</tr>
</form>
</table>
</td>
</tr>
</table>

</body>
</html>
ammweb
 
Posts: 3
Joined: Sat Mar 24, 2007 11:14 pm

Postby rangana on Tue Jun 24, 2008 2:17 am

I've made a response on to your other thread in CF.

...and the script is:
Code: Select all
<script type="text/javascript">
window.onload=function()
{
var df=document.forms[0];
df.onsubmit=function()
   {
   var opts=document.getElementsByTagName('select');
   for(var i=0;i<opts.length;i++)
      {
      if(opts[i].value=='0')
         {
         alert('You need to choose at least one option');
         return false;
         }
      else
      return true;
      }
   return;
   }
}
</script>


Hope it was helpful.
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby ammweb on Tue Jun 24, 2008 3:18 pm

rangana wrote:I've made a response on to your other thread in CF.

...and the script is:
Code: Select all
<script type="text/javascript">
window.onload=function()
{
var df=document.forms[0];
df.onsubmit=function()
   {
   var opts=document.getElementsByTagName('select');
   for(var i=0;i<opts.length;i++)
      {
      if(opts[i].value=='0')
         {
         alert('You need to choose at least one option');
         return false;
         }
      else
      return true;
      }
   return;
   }
}
</script>


Hope it was helpful.
I tried adding your code to the code posted.

I got the error when nothing was selected, but I also got the error when I selected any of the list menu but the first menu list. If I selected the first menu list, the form submitted.

My question would be, how to validate all the menu lists? And if any one of the menu lists list a qty, than submit the form.

Thanks for your help so far.
ammweb
 
Posts: 3
Joined: Sat Mar 24, 2007 11:14 pm


Who is online

Users browsing this forum: No registered users and 4 guests