Reputation:
When I submit #top_cat
, the firebug console says "ok"
because of the debug text I'm printing here:
function submitHandler() {
console.log("ok");
$.post($(this).attr('action'), $(this).serialize(), null, "script");
return false;
}
But if I click on #tip_click
, I see "start"
and "end"
in the output but it never says "ok"
- meaning the submitHandler
never ran.
Is there anything obviously wrong with this code?
$(document).ready(function () {
$('#top_cat').submit(submitHandler);
$("#tip_click").click(function() {
console.log("start");
$("#high_hat").submit(submitHandler);
console.log("end");
});
});
Upvotes: 0
Views: 65
Reputation: 41858
Why not try:
$("#tip_click").click(function() {
console.log("start");
submitHandler();
console.log("end);
});
I don't see any benefit to submitting it manually, since it returns false anyway, so just calling the submitHandler directly will simplify the code.
I don't see any benefit to submitting as John suggests since you return false anyway.
Upvotes: 0
Reputation: 361605
$("#high_hat").submit(submitHandler);
This registers an onsubmit
handler but does not run the handler. It sets up the handler to be called whenever #high_hat
is submitted. If you want to run the submit handler right away you'll need to trigger it yourself by calling submit()
(no arguments):
console.log("start");
$("high_hat").submit(submitHandler).submit();
console.log("end");
Upvotes: 2