|
Multiple Drop Down Validation
|
| View previous topic :: View next topic |
| Author |
Message |
Jake Enthusiastic Coder
Joined: 15 Mar 2005 Posts: 68
|
The code below is a working code to validate an empty selection in the drop down list.
What changes I must do in the Form OnSubmit if I want to validate more that one dropdown list in my form.
How many script can a page handle at one time! I mean the javascript that we put in the <head></head> section? Is there any limit?
Code:
<html>
<head>
<title>Untitled Document</title>
<script language="javascript">
function fCheck(val1){
if (val1 == ""){
alert("Please select a value");
return false
}else{
return true
}
}
</script>
</head>
<body>
<form action="http://www.mcfc.co.uk" method="post" onSubmit="return fCheck(bnRoom.value);">
<select name="bnRoom">
<option></option>
<option value="MONDAY">MONDAY</option>
<option value="TUESDAY">TUESDAY</option>
<option value="MONDAY">WEDNESDAY</option>
<option value="THURSDAY">THURSDAY</option>
<option value="FRIDAY">FRIDAY</option>
</select >
<input type="submit" value="click me!">
</form>
</body>
</html>
Reply with quote
|
| |
|
|
Jony Enthusiastic Coder
Joined: 18 Mar 2005 Posts: 71
|
I believe that each object in your form can use onfocus() and onblur() which will be called each time someone clicks onto (focuses) on an object and clicks off of (blurs) an object.
Using that, you could make it so that required fields automatically alert the user when they are not filled in.
Of course, if the user doesn't click on them then they never get the message... I don't believe that you can call more than one function from onSubmit though, so you would have to design another function which explicitly tested your form and each of the required fields.
Reply with quote
|
| |
|
|
|