Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  64] [ 3]  / answers: 1 / hits: 196538  / 13 Years ago, wed, april 20, 2011, 12:00:00

I have a form that looks like this



<form action=receiver.pl method=post>
<input name=signed type=checkbox>
<input value=Save type=submit>
</form>


and I would like to stay on the same page, when Submit is clicked, but still have receiver.pl executed.



How should that be done?


More From » html

 Answers
1

The easiest answer: jQuery. Do something like this:



$(document).ready(function(){
var $form = $('form');
$form.submit(function(){
$.post($(this).attr('action'), $(this).serialize(), function(response){
// do something here on success
},'json');
return false;
});
});


If you want to add content dynamically and still need it to work, and also with more than one form, you can do this:



   $('form').live('submit', function(){
$.post($(this).attr('action'), $(this).serialize(), function(response){
// do something here on success
},'json');
return false;
});

[#92638] Monday, April 18, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
samara

Total Points: 326
Total Questions: 106
Total Answers: 103

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
;