Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Validate more then one selection list?

 
Steve Sol
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
 
Austin Tashis
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic