0

In the code below, "clicked" is logged out, but "submitted" is never logged. Anyone know why? The IDs are correct.

$('#submitModal').click(function(){ console.log("clicked"); $('#createEvent').submit(function() { console.log('submitted'); return false; }); }); 
2
  • What element has ID createEvent? Could you please put your example to jsfiddle.net for testing? Commented May 13, 2012 at 19:46
  • @SergeyRybalkin the form has the ID createEvent Commented May 13, 2012 at 19:47

1 Answer 1

3

This code binds a handler. It doesn't trigger one.

$('#createEvent').submit(function() { console.log('submitted'); return false; }); 

You'd need to bind it first, then trigger it when needed.

 // bind the click $('#submitModal').click(function(){ console.log("clicked"); $('#createEvent').submit(); // trigger the pre-bound submit handler }); // bind the submit $('#createEvent').submit(function() { console.log('submitted'); return false; }); 

Also you may have some issues if $('#submitModal') is a submit button to a form element. Not sure.

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

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.