0

I'm trying to validate text field using javascript. return false is working fine. but return true is not working.

HTML

<form namme="frms" action="booking_management.php">
    <input type="text" name="total" id="totald" value="" onkeyup="calbill()" class="input"/>
    <input name="but" type="button" value="Send Bill" class="btn btn-primary" onClick="bill()" />
</form>

JavaScript

function bill() {
  if (Checktot()) {
    document.forms["frms"].submit();
  }
}

function Checktot() {
  var tot = document.getElementById("totald").value;
  if (tot == "no") {
    document.getElementById("totald").style.borderColor = "#ED291F";
    alert("Please try again");
    return false;
  }
  return true;

}
2
  • 1
    better use jquery validate plugin. see this link jqueryvalidation.org/files/demo Commented Mar 5, 2015 at 5:24
  • 1
    You have typo: namme="frms" Commented Mar 5, 2015 at 5:35

1 Answer 1

1

You are getting error:

Uncaught TypeError: Cannot read property 'submit' of undefined

document.forms["frms"].submit();

ERROR DEMO


You can use this:

document.forms[0].submit()

Working DEMO

Sign up to request clarification or add additional context in comments.

Comments

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.