• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to Validate more then one selection list?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..
Please could someone help me. I want to be able to make a user fill in both of these selection lists, and if not .. the user would be prompted to, before the form can be sent.
Im only able to validate the first list, unsure on how to add the second list in.
Here is my code.
----------------------------------------------------------------------------------------
<html>
<head>
<title></title>
<script language="JavaScript">
<!--

function checkList(selection) {

if (selection.length == 0) {
window.alert("Make a selection.");
return false;
}

return true;

}


function checkForm(formObj) {
return checkList(formObj.myField.value);
}



// -->
</script>

</head>

<body>

<form name="myForm" action="java.html" onSubmit="return checkForm(this);">

Choose 1
<select name="myField">
<option value=""></option>
<option value="1">1</option>
</select>



Choose 2
<select name="myField2">
<option value=""></option>
<option value="2">1</option>
</select>



<input type="submit">
</form>

</body>
</html>

--------------------------------------------------------------------------------

Thanks
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you post code please use code tags so it is easier to read.

You need to use the and [&&] operator



Eric
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The quickest way to validate a form is to iterate the elements collection and use a switch statement to choose validation criteria by name, id, class, tagName, type or whatever, depending on how specific your validation needs to get.
 
Just the other day, I was thinking ... about this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic