Im trying to pass some values into a text box from a child page to the parent page. The code I have works fine passing one integer value through to the parent page, however it won’t pass a string. I also want to try and pass another value through to an additional text box, how would I go about doing that?
logRequestAdmin is the name of the form on the parent page, and ClientName is the text box to post the first value to.
Here’s my code for the child page:
<head>
<script type="text/javascript">
<!-- Begin
function moveData(info) {
window.opener.document.logRequestAdmin.ClientName.value = info;
self.close();
return false;
}
// End -->
</script>
<table>
<tr>
<td class="clientTop">Client ID</td>
<td class="clientTop">Client Name</td>
<td class="clientTop">Username</td>
<td class="clientTop">Email</td>
</tr>
$query = "Select * from clients";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
while($row = mysql_fetch_array($result))
{
$ClientID = $row['ClientID'];
$ClientName = $row['ClientName'];
$Username = $row['Username'];
$Email = $row['Email'];
echo '<tr>
<td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $ClientID . '</a></td>
<td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $ClientName . '</a></td>
<td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $Username . '</a></td>
<td class="clientBottom"><a href="javascript:void();" onclick="moveData(' . $ClientID . ');">' . $Email . '</a></td>
</tr>';
}
</table>
It looks like the problem is in your javascript function call in the
Atags. Here is how your code works if you pass integers and strings…The above lines write HTML like:
JavaScript thinks you’re passing a
1the first time, and should throw an error onThe Dudesince the function call is malformed.If you add some extra apostrophes, it should work just fine.
PHP:
HTML:
If you want your rows to look cleaner, you could also alter your js function to pass the
innerHTMLproperty of the link tag…