0

I am experiencing some confusing side effects when trying to handle a submit event. Instead of processing the jquery event handler, the script xyz.php is being called.

<script type = "text/javascript"> $(document).ready(function(){ $("#myForm").submit(function() { alert "It works (or not)."; return false; }); }); </script> <div id="contact"> <form action="xyz.php" method="post" id="myForm"> <input type="text" class = "webform" size="30" id="nam" name="nam" ></input> <input class = "webform" type="submit" name="submit" id="send" value="send" ></input> </form> </div> 

This is a little bit confusing. I dont see what I am doing wrong. Does anyone has an idea ?? Any help is apreciated. Thank you, so much, in advance...

1
  • FYI, input is a self closing tag, you shouldn't have closing tags </input> Commented Jul 15, 2013 at 8:30

3 Answers 3

2

Wrap alert message in () like this:

alert ("It works (or not)."); 
Sign up to request clarification or add additional context in comments.

Comments

2

Besides the missing "()" in alert.. Your form is being directly submitted when the page is loaded and because of your "action" in your form, xyz.php is being shown.

Try this instead: $('#send').click(function(){ $("#myForm").submit(); });

Comments

0

alert is a function, you have to use it with parantheses - alert() -, can you please rewrite your code and try again?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.