I have multiple forms on a jQuery mobile page that all use the same php processor. I was able to figure our how to get jQuery to submit only the form that contains the submit button the user clicked but I am unable to figure out how to change the value of the button the user clicked.
I would like it if the button text could change for only the button the user clicked.
So far the script below will change the text of all the submit buttons not just the one the user clicked.
My jQuery:
$("form input[type=submit]").on("click", function(e){
$.post('doStuff.php', $(this).closest("form").serialize(), function(data) {
//changes the value of all submit buttons
$('input[type=submit]').val('Thank You').button( "refresh" );
//the rest of these do not work at all
$('input[type=submit]', $(this).closest('form')).val('Thank You').button( "refresh" );
$('input[type=submit]', $(this)).val('Thank You').button( "refresh" );
$('input[type=submit]', $(this).parent('form')).val('Thank You').button( "refresh" );
}).error(function(){
alert("Error submiting the form");
});
});
My HTML:
<form action="doStuff.php" method="post" data-ajax='false'>
<input type="submit" name="submit" value="stuff" id="btnSubmit">
</form>
<form action="doStuff.php" method="post" data-ajax='false'>
<input type="submit" name="submit" value="more stuff" id="btnSubmit">
</form>
<form action="doStuff.php" method="post" data-ajax='false'>
<input type="submit" name="submit" value="a ton of stuff" id="btnSubmit">
</form>
Does anyone have an idea how to accomplish what I am looking to do?
Do it the other way, listen to
submit
event, post the form and change text of button within that form.