On your 2 submit buttons, try the
onClick event.
I have this working. If you want to use it, I'm sure you can make the changes needed. The onClick passes the form name to check data. So in YOUR case, the error message will not be 100% correct.
The other option here would be 2 functions. One to check each form. With this you would have the correct error message to display.
Code:
<html>
<head>
<title>forms</title>
<script type="text/javascript">
function dataok(formName) {
var strFields = "";
var strData;
strData = document.forms[formName].name.value;
if (strData.length == 0) {
strFields += " NAME";
}
strData = document.forms[formName].email.value;
if (strData.length == 0) {
strFields += " EMAIL";
}
strData = document.forms[formName].message.value;
if (strData.length == 0) {
strFields += " MESSAGE";
}
if (strFields.length > 0) {
alert("The following field(s) were blank" + strFields);
}
}
</script>
</head>
<body>
<form name="contact">
name: <input type="text" name="name"><br>
email: <input type="text" name="email"><br>
message: <input type="text" name="message"><br>
<input type="submit" name="submit" value="Contact Me!" onClick="return dataok('contact')">
<input type="reset" name="reset" value="Reset" onclick="return confirm('Are you sure you want to clear all fields of the form?');">
</form>
<p></p>
<form name="sms">
name: <input type="text" name="name"><br>
email: <input type="text" name="email"><br>
message: <input type="text" name="message"><br>
<input type="submit" name="submit" value="Contact Me!" onClick="return dataok('sms')">
<input type="reset" name="reset" value="Reset" onclick="return confirm('Are you sure you want to clear all fields of the form?');">
</form>
</body>
</html>