Hi.
I need to do the following, but I couldn't find any example of similar form validation on the web:
<script type="text/javascript">
function something(){
if the value on the field who is calling this function == 2,4,6 or 8
alert("This number is invalid")
focus in this field.
</script>
Field1 call something()
Field2 call something()
Field3 call something()
Field4 call something()
Field5 call something()
Field6 call something()
I've tried like this:
function validate()
{
valid = true;
if ( document.form.field_name.value == "2" || document.form.field_name.value == "4" || document.form.field_name.value == "6" ||
document.form.field_name.value == "8" ){
alert ( "Invalid number." );
valid = false;
document.form.field_name.focus();
}
return valid;
}
I'm calling the function like this:
a)"Some text" <input type="text" name="aa" size="1" maxlength="1" onkeypress="return validate(aa)"><br>
But this way I would have to create a different function for every field. So how could I implement this?