I have a form that uses javascript form validation and instead of listing each variable and what to validate it against per variable, I am trying to combine all of those variables into one variable and then have them validate against a singular list of elements.
I was trying initially to assign all of the input fields to a class and have them validate against the class instead of the name element but I could not get that to work so I am trying this.
Here is my code:
<!DOCTYPE html>
<html>
<head>
<script>
function validateForm() {
var x = document.forms["myForm"]["input1"].value;
var y = document.forms["myForm"]["input2"].value;
var z = x + y;
if (z == "123CODE" || z == "125CODE") {
return true;}
else if (z != "123CODE" || z != "125CODE") {
alert("Please enter a valid code"); return false;}
}
</script>
</head>
<body>
<form name="myForm" action="demo_form.asp"
onsubmit="return validateForm()" method="post">
Name: <input type="text" name="input1">
<input type="text" name="input2">
<input type="submit" value="Submit">
</form>
</body>
</html>