1

I tried to intercept a submit form by javascript script but it doesn't work .

this is my html code :

<form id="myForm" action="home1" method="post">
    <input type="text" id="user_email" name="email" /> 
    <input type="password" id="user_password" name="password" />
    <button type="submit" class="btn bg-olive btn-block">Sign up</button>
</form>

Script:

$("#myForm").submit(function(event) 
{
    /* stop form from submitting normally */
    event.preventDefault();
    alert('success');
});
});
4
  • 4
    Check the developer console. Your code looks like it has syntax errors. Commented Aug 14, 2014 at 23:57
  • Once you use proper formatting it's obvious what the issue is... Commented Aug 15, 2014 at 0:33
  • Sorry, I'm a new member. Commented Aug 15, 2014 at 0:38
  • No, once you use correct formatting in your code... Commented Aug 15, 2014 at 0:43

1 Answer 1

1

You have a superfluous });in line 23.

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

3 Comments

thanks, you are right. But what makes me post this idiot code is that I don't understand why the script must be declared in the body(exactly after the form). l mean why it doesn't work when I declare it in the head!?
Because the elements don't exist at that point. You should use jQuery's ready handler.
Now i understand .Thank you Lee .

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.