1

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.

1 Answer 1

1

Try:

function validateForm()
{
  var x=document.forms["billingForm"]["first"].value;
  if (x==null || x=="")
  {
    alert("Empty field");
    return false;
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

What I need is the js file to do the validating. Hence, or is there a way I can do the validating and send it to the .Js file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.