Would something like this work?
.js
var error = "";
function textBox(checkForBlanks)
{
if (checkForBlanks == "")
{
error(errorMessage);
}
}
HTML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="new.js"></script>
<script>
function validateAll()
{
var first = document.billingForm.first.value;
var errorMessage = "";
if (first == textBox)
{
errorMessage += "Enter name";
}
if (errorMessage != "")
{
alert(errorMessage); or
alert(error);
}
}
</script>
</head>
<body>
<form action="http://cswin2k5/echo/default.asp" method="post" name="billingForm">
<p>First Name*:
<input type="textbox" name="first" id="first" onBlur="this.value=trim(this.value)" onkeyup='capitalize(this)'></p>
<p><input type="button" value="Proccess Payment" onClick="return validateAll();"/></p>
</form>
</body>
</html>
Or something like this? What this is trying to do is check if the text box is empty, that way I can use the same function for all text box. I'm trying to pass this through to HTML for validation.
Try:
function validateForm()
{
var x=document.forms["billingForm"]["first"].value;
if (x==null || x=="")
{
alert("Empty field");
return false;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.