April 12, 2012

multiple form submission with one submit

Question by skylab

I’ve been trying to think this through and figure out if it is possible or not. I’m using zen-cart as shopping cart software, but what I’d like to do, is hard code a page that is basically a list of 7-9 products, next to each product is a checkbox, so I’d like to figure out a way, via html,javascript or jquery to submit whichever forms(products) are checked to the cart. The typical form submission for a product looks something like this(sometimes there may be one or two additional hidden fields):

<form name="cart_quantity" action="index.php?action=add_product" method="post"      enctype="multipart/form-data">
    <input type="hidden" name="cart_quantity" value="1">
    <input type="hidden" name="products_id" value="7">
    <input type="hidden" name="id[6]" value="9" id="attrib-6-9"> 
    <input type="image" src="buy_button.png" alt="Add to Cart" title="Instructional Video Part 1: Add to Cart">

There would be 7-9 of these on the page, each with a checkbox, so I’m assuming a script would need to figure out which ones where checked and submit them via the form action? Maybe there is a better way of going about this that I’m not thinking of because a)it’s over my head or b)just haven’t figured it out yet. Anyway is something like this possible?

Answer by Starx

You can do it, as this

$("#yourcommonbuton").click(function() {
    if($("#checkbox1").prop('checked') == true) $("#form1").submit();
    if($("#checkbox2").prop('checked') == true) $("#form2").submit();
    if($("#checkbox3").prop('checked') == true) $("#form3").submit();
    return false;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!