Tuesday 15 May 2012

jquery - Perform action before form submit? -



jquery - Perform action before form submit? -

i have html form id , have binded id submit function. want when user clicks submit, popup comes modal box thanking them. , after click off screen or when modal box closes when want form submit , refresh page.

but way have seems refresh no matter what. using fancy popup plugin modal box.

<form action="submit-comment.php" method="post" id="form"> <input type="text" name="comment" /> <input type="submit" name="submit" value="submit" /> </form> jquery("#form").submit(function() { jquery.fancybox('<div class="box">some content</div>', { 'onclosed' : function() { homecoming true; } } }); });

as can see trying tell homecoming true on close isn't working.

any ideas?

try this:

jquery("#form").submit(function(e) { var self = this; e.preventdefault(); jquery.fancybox('<div class="box">some amazing wonderful content</div>', { 'onclosed' : function() { self.submit(); } }); homecoming false; //is superfluous, set here fallback });

javascript asynchronous cannot delay homecoming statement.

update

to create code above works, alter name of submit button else, example:

<input type="submit" name="submit_me" value="submit" />

jquery forms

No comments:

Post a Comment