views:

36

answers:

1

Let's say we have this form:

<form>
  <input type="text" name="some_name" value="val" id="some_name">
  <input type="image" value="action" alt="Add To Cart" name="add" src="/images/submit.gif">
  <input type="image" value="action" alt="Shop some more" name="return" src="/continue_shopping.gif">
</form>

How do I find the input that submitted the form?

A: 

You could add IDs to your different input items :

<input id="SomeName" type="text" name="some_name" value="val" id="some_name">
<input id="AddCart" type="image" value="action" alt="Add To Cart" name="add" src="/images/submit.gif">
<input id="Return" type="image" value="action" alt="Shop some more" name="return" src="/continue_shopping.gif" />

And then, in your jQuery, access the events with

    $("#Return").click(function(){
    //do your stuff
    });
Hugo Migneron
I'm trying to trigger the action on form submit just in case they don't click on one of the images, but hit [return] out of a text input. One of the buttons submits the item to the cart, the other lets the customer continue shopping without adding the item.
brennanag
This worked great! Because I didn't have access to the element in the source (CGI tag on my templated store), I just added the id and then bound the click action to the id I previously added.
brennanag