0

I have a form like this:

<form method="post" action="user_submit.php" id="addUserForm">
 <p>
 <label for="username">Enter Username:*</label>
 <input type="text" name="username" id="username">
 </p>
 <p>
 <label for="firstname">Enter First Name*</label>
 <input type="text" name="firstname" id="firstname">
 </p>

:

 <input type="hidden" name="addUser" value="1" />
 <p><input type="button" name="submit" value="submit" id="submit_AddUser" onClick="validate_addUser();" ></p>

this is the simple js im using

function validate_addUser(){
 if (!$('#username').val())
 alert('Please enter Username');
 else if (!$('#firstname').val())
 alert("Please enter first name");
 else if (!$('#lastname').val())
 alert("Please enter last name");
 else if (!$('#email').val())
 alert("Please enter email address");
 else 
 $('#addUserForm').submit();
}

When I submit the form, this is the error that im getting

e[h] is not a function
[Break On This Error] 
...{href:function(a){return a.getAttribute("href")
Ja͢ck
174k39 gold badges269 silver badges317 bronze badges
asked Jun 19, 2012 at 2:03
12
  • Your code seems okay, perhaps you should retry with jQuery development version; that should give you more details Commented Jun 19, 2012 at 2:07
  • 1
    how is form submitting? if you don't have a submit handler, validation function won't stop it submitting regardless if it validates or not Commented Jun 19, 2012 at 2:12
  • @charlietfl You can just call submit() on a form with no problem, it's even an example in the jQuery .submit docs. Commented Jun 19, 2012 at 2:16
  • 1
    @DaveNewton I realize you can call submit, but without returning false in clcik handler there is nothing stopping default submit if validation test fails Commented Jun 19, 2012 at 2:19
  • @DaveNewton, charlietfl is right, without preventing default behavior you can't check the form. Commented Jun 19, 2012 at 2:20

1 Answer 1

1

I changed the name from submit to go and it started working, dyaamn!!

<input type="button" name="go" value="go" id="gogogo" onClick="validate_addUser();" >
answered Jun 19, 2012 at 3:09
Sign up to request clarification or add additional context in comments.

1 Comment

Weird, but taking the name "submit" out worked for me as well.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.