Reputation: 1389
I've made a script to submit a form and then opens a dialog showing "added to cart". It works in FF. Chrome redirects me to the cart page and IE does nothing, not even submit anything.
<script type="text/javascript">
var productId = {{ product.vid }};
var addUrl = "http://shop.com/cart/add/" +productId+ "/?quantity=";
jQuery(document).ready(function(){
bakVormAsset("#formProduct");
});
function bakVormAsset(product){
jQuery(product + " #formProductQuantity").val("1");
jQuery(product + " #formProductQuantity").keyup(function () {
var val = jQuery(product + " #formProductQuantity").first().val();
});
jQuery(product + " .opener").click(function(event) {
event.preventDefault();
$.get($(this).attr('href'), function(data, status) {
var val = jQuery(product + " #formProductQuantity").first().val();
// Go to page
window.location.href = addUrl + val;
$( "#dialog" ).dialog( "open" );
return false;
});
}
</script>
And my form looks like this:
<form class="formProduct" id="formProduct" action="#" method="post">
<input type="text" name="quantity" id="formProductQuantity" value="{{ product.stock.minimum }}" />
<a class="button blue opener" href="" title="{{ 'Add to cart' | t }}"><span>{{ 'Add to cart' | t }}</span></a>
</form>
Please help me
EDIT What I forgot to mention is that off course when the form submits the user must stay on the same page and NOT being redirected to the "cart" page.
Upvotes: 0
Views: 621
Reputation: 2889
http://jquery.malsup.com/form/
if You want to submit your form via ajax or something you have to use this plugin.
And on Complete Method you can do what ever you want to do.
jQuery(product + " .opener").click(function(event) {
event.preventDefault();
var options = {
success: function(){
$( "#dialog" ).dialog( "open" );
} // post-submit callback
};
$('#myForm2').ajaxSubmit(options);
});
You have to specify the action of the form. which action this form has to be submitted.
Upvotes: 1