This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
Submitting hidden values on the form with onSelect option
jQuery Validator and select
Code works if I use alert(), doesn't if I don't
how to access combo-box value in javascript?
Setting the attribute of a tag dynamically.