I have a form, and in that form I have a div that list a table of pet owners.
This table is loaded from a file called findowner.php.
After clicking on the row of a pet owner I want to use the variable I got $(this).attr('rowid'). This is the owners id. In the php file I get it like this:
Other td elements here for name, address, etc.
'<td>'.'<a id="tableid" href="#" rowid='.$rowid.' >'.$rowid.'</a>'.'</td>'.
var vpetowner = $(this).attr('rowid');
I can't seem to get the val(vpetowner) into the forms $('#petowner').
If I load the findowner by itself (for testing), the alert(vpetowner); line works. But if clicked from the div where loaded from the other file (editpets.php), it doesn't alert and the $('#petowner').val(vpetowner); doesn't update.
How would I properly pass this from the div to parent?
This is where a demo testing page that we can look at too, and apply our debugging techniques to, will be of great help for us to help you.
I am new to jquery, and there seems like it has some limits on passing values.
Code fragment from child window that has an onclick attached to the tr.
if ($powners_Row = $db->fetch($powners_Res))
$kount = 0;
$kount = $kount + 1;
$rowid = "a".$kount;
$vid = $powners_Row['ownerid'];
'<tr id='.$rowid.' onMouseover=this.bgColor="lightgrey" onMouseout=this.bgColor="#FFFFFF" onclick="cell(this.id)">'.
while ($powners_Row = $db->fetch($powners_Res));
Now the function that handles this:
opener.document.peditform.ownerid.value = x.firstChild.nodeValue;
opener.document.peditform.petowner.value = x[1.firstChild.nodeValue;
opener.document.peditform.ostreet.value = x.firstChild.nodeValue;
This code works perfect.
OK, the questions.
1) How to add a onclick to a <tr> in jquery? Note each row has unique id.
2) How to send the three values obtained back to parent?
I don't use this technique now, I used to, I now return the ownerid from the table row, then do a lookup through ajax to get the rest of the data. Much like dhtmlgoodies.com's dynamic client lookup example. I also use the SACK library.
For Dynamic client lookup on left click ajax scripts, then scroll down.