aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to Validate more then one selection list? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to Validate more then one selection list?" Watch "How to Validate more then one selection list?" New topic
Author

How to Validate more then one selection list?

Steve Sol
Greenhorn

Joined: Apr 18, 2009
Posts: 4
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: May 23, 2003
Posts: 19
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Validate more then one selection list?
 
Similar Threads
Code works if I use alert(), doesn't if I don't
Setting the attribute of a tag dynamically.
jQuery Validator and select
how to access combo-box value in javascript?
Submitting hidden values on the form with onSelect option