Apologies if this has been posted already, I did a search on "click" but
couldn't find anything easily.

I'm new to jquery and am having problems figuring out how to find items.

I have a dynamic set of forms on a php page. For each database entry, a new
form is outputted. Here is the HTML code in question (this is found within a
foreach loop, so there are multiples of these inputs in the entire page):

<input id="ship<?=$counter?>" type="checkbox" />
<input id="id<?=$counter?>" type="hidden" value="<?=$payment->id?>" />
<input id="counter" type="hidden" value="<?=$counter?>" /><br />
<input type="submit" class="form" />

I append the counter variable to "ship" and "id" to distinguish which set of
form variables were submitted. I use the "counter" hidden variable to know
which form fields to look up (for example if the counter is 3, i'd be
looking up the input fields with ids 'ship3' and 'id3'. 

My jquery code:

$('input.form').click(function()
{
        var counter = $('input#counter').val();
        var ship = 'ship' + counter;
        var temp = 'id' + counter;

        var id = $('[EMAIL PROTECTED]@id=' + temp + ']').val();

        //If the checkbox was actually checked
        if ($('input#' + ship + '').val() == "on")
        {
                $.ajax(
                {
                         type: "POST",
                         url: "updateshipping.php",
                        data: "id="+id+"",
                });
        }
});

I had to do the [EMAIL PROTECTED] bit to get the value of a hidden field (is
there an easier way? trying it without gave a null result). 

My goal is to get the value of the input field (with id of "counter") INSIDE
THE FORM that was clicked via "index.form". Right now, the code is returning
the first input field with id of counter, regardless of if it is the one
inside the clicked form. 

Does anyone know how to do this? Any help would be appreciated. If you know
a way to make my code better that would be great too, I'm quite new to this
:)

thanks!
-- 
View this message in context: 
http://www.nabble.com/Find-element-within-clicked-form-tf2838397.html#a7924567
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to