I have sets of records on a page each has an edit link, clicking the link loads an edit form into the record the user wants to edit, so a user can click edit beside every link creating an unknown number of forms on the page. <li id="r_123" >user records "edit" </li> <li id="r_456" >user records "edit" </li> <li id="r_789" >user records "edit" </li> Each form loaded into the reords li has its own unique id so submitting the form is fine my problem is that its only submitting to the record / form that opens last. So if the user clickes edit, edit , edit for each of the example records above its only submitting to the last record.
I know where the problem is, I just don't now how to fix it. When the user clicks "edit" the js gets the variable from the newly loaded form_id and that gets passed in the uRec(form_id); saying to edit this "form" so as soon as the user clicks edit again the first form_id is gone and replaced with the newly opened form. Any ideas where I am going wrong here? I cant change the idea to have only 1 form at a time open setup. If I could add a bind sumbit to the script to grab the form_id of what was just submitted then run the function i think that would do the trick. Pretty new at this and not sure where I would go about adding the bind submit. Something like: var form_id = '#<?php echo $form_id ?>'; $(form_id).bind("submit", uRec(form_id) { return false; }???? My script onthe page with all the records is : <script type="text/javascript"> var form_id = '#<?php echo $form_id ?>'; uRec(form_id); </script> My external js: function uRec(selector){ var $form = $(selector); $form.submit( function() { var data = $(form_id).serialize(); var form_url = $(form_id).attr('action'); var form_target = form_url.substr(1).replace( new RegExp( "/" ,"g"), "_" ); var update_target = (form_target.replace("_edit", "")); $.blockUI({ message: null}); $form.ajaxSubmit({ type: "post", url: form_url +'/', data: data, dataType: 'json', success: function(response){ if (response.status === true) { $.unblockUI(); $('#' + update_target).html(response.html).slideToggle('slow').highlightFade({speed: 2000}); $('#' + form_target).slideToggle('slow'); } else { $.unblockUI(); $('#' + form_target).html(response.html); } } }); return false; }); }; Dave