Trigger a specific input button in a form from another forms input buttons
I want to trigger a specific input button in a form from another forms input buttons. As if someone clicked o开发者_如何学Gon that button not just submit the form as in the answer in this thread. This is the one I want triggered.
<td width="135" align="right"><input border="0" type="image" id="btnRecalculate" name="btnRecalculate" src="v/vspfiles/templates/100/images/buttons/btn_recalculate.gif" alt="Recalculate Totals"></td>
previous question
<form method="POST" name="form" action="ShoppingCart.asp" onsubmit="if (typeof(Update_Hidden_State_Fields)=='function') Update_Hidden_State_Fields(); if (this.submitted) return false; else {this.submitted=true; return true;}"> <td><center><input type="text" maxlength="7" size="5" value="5" name="Quantity1" id="Quantity1"><center></td>
<td><center><input type="text" maxlength="7" size="5" value="2" name="Quantity2" id="Quantity2"><center></td>
<td><center><input type="text" maxlength="7" size="5" value="5" name="Quantity3" id="Quantity3"><center></td>
<td width="135" align="right"><input border="0" type="image" id="btnRecalculate" name="btnRecalculate" src="v/vspfiles/templates/100/images/buttons/btn_recalculate.gif" alt="Recalculate Totals"></td></form>
this is the second form
<form name="Proceed_To_Checkout_Form" method="post" action="https://www.dothisurl.com/login.asp">
<td><input type="image" src="v/vspfiles/templates/100/images/buttons/btn_checkout_guest.gif" name="btn_checkout_guest"></td>
<td><input type="image" src="v/vspfiles/templates/100/images/buttons/btn_checkout_guest.gif" name="btn_checkout_guest"></td></form>
This is the previous answer given
$(function(){
$("[id^='Quantity']").each(function(){
$(this).data('default', $(this).val());
});
$("[name='Proceed_To_Checkout_Form']").submit(function(){
var hasChanged = false;
$("[id^='Quantity']").each(function(){
if($(this).val() != $(this).data('default')){
hasChanged = true;
}
});
if(hasChanged){
$("[name='form']").submit();
return false;
}
});
});
Try this: $('#btnRecalculate').trigger('click');
More info here: http://api.jquery.com/trigger/
精彩评论