I fail to see where your problem was related to your question ; anyway, what I just explained will work with AJAX (that was even the point really), you just have to add the .load() or the .get() and give them the appropriate parameters to have a nice and shiny ajax interface for your users to enjoy.
Michel Belleville 2009/12/8 Themba Ntleki <themba.ntl...@gmail.com> > Thanks Michel, > > I found a solution, my mistake was trying to create the function inside : > $(document).ready(function() { > > the onClick could not find the function. I have defined the function > separately and the onclick does work. Basically, I want to do the edit > action using ajax, but thanks a mil for the response!! > > > > 2009/12/8 Michel Belleville <michel.bellevi...@gmail.com> > > First of all you'll need to write your $ec_arr[4] somewhere in your page, >> or your client-side jQuery script won't be able to even guess it. Ideally it >> should be placed as near as possible from your edit link. Wait, what's a >> link for ? Bringing the client to another url, the href attribute exists for >> this very purpose. And we want to pass an argument / parameter when we click >> on that link... Hey, why not put it right on the href attribute then ? >> >> <td><a href="<?php echo $ec_arr[4] ?>">Edit</a></td> >> >> Hmm, something seems a bit out of place. I mean, unless whatever is in >> $ec_arr[4] is an actual url, it's not quite proper to put just this in a >> link's href right ? Right. So, let's assume you've got an edit script >> located there : "http://somewhere.over.therainbow.com/way/up_high.php", >> which takes "id" as a parameter, and that this id is what's in $ec_arr[4] : >> >> <td><a href="http://somewhere.over.therainbow.com/way/up_high.php?id=<?php >> echo $ec_arr[4] ?>">Edit</a></td> >> >> This way, even when your user wouldn't have JavaScript, this is still >> working for him if a bit less friendly. Now how do I easily set up a click >> callback on each link of a table ? >> >> $('table a').click(function() { alert('OMG someone clicked me !'); }); >> >> And how do we get the clicked element in a click callback ? >> >> $('table a').click(function() { alert('OMG someone clicked me again ! And >> I totally have this href thingy : ' + $(this).attr('href')); }); >> >> Now I'll let you figure out how to put all this together with whatever >> .load() or .get() or something else you'd like to do to get your form back >> on your page. >> >> Michel Belleville >> >> >> 2009/12/8 theUnseen <themba.ntl...@gmail.com> >> >> Hi guys, >>> >>> I show a table with mysql data with an edit option/link for each >>> record, but i want the edit link to call a jquery function onclick and >>> it must pass the $ec_arr[4] as the argument/parameter which is the id >>> of the record in the mysql table to JQuery. how can I do this >>> please...? >>> >>> <table border="1"> >>> <tr> >>> <td>Fullname</td> >>> <td>Relationship</td> >>> <td>Contact number</td> >>> <td>Residential address</td> >>> <td> </td> >>> </tr> >>> <?php foreach(get_emergency_contact_fields($var) as $ec_arr): ?> >>> <tr> >>> <td><?php echo $ec_arr[0] ?></td> >>> <td><?php echo $ec_arr[1] ?></td> >>> <td><?php echo $ec_arr[2] ?></td> >>> <td><?php echo $ec_arr[3] ?></td> >>> <td><a href="#">Edit</a> </td> >>> </tr> >>> <?php endforeach; ?> >>> </table> >>> >> >> > > > > > > > >