Hi i'm having a slight issue with loading variable into another page without refreshing first page. So here's the deal. I have two windows(pages), when i click a button(agents) in the parent window a child window opens with a list of agents from mysql database. Here are the parent and child pages respectively:
client_details.php
<?php include "includes/config.php"; ?>
...
//For Agents
if ( isset( $_GET['agentid'] ) && is_numeric( $_GET['agentid'] ) ) {
$sql = "SELECT agentID, CONCAT( firstName, ' ', lastName ) AS agent FROM tblagents WHERE agentID = {$_GET['agentid']}";
if ( $result = mysql_query( $sql ) ) {
if ( mysql_num_rows( $result) == 1 ) {
$agentDetails = mysql_fetch_array( $result );
}
}
}
...
<body>
<p>Agent Name:
<input type="agent" name="agentName" value="<?php
if ( isset( $_POST['agentName'] ) ) {
echo $_POST['agentName'];
} elseif ( isset( $agentDetails['agent'] ) ) {
echo $agentDetails['agent'];
}
?>"/>
<div style="margin-left:90px; margin-top:-10px">
<input type="button" value="Agents" name="agent_btn" class="btndesign" onclick="window.open('agents.php','popUpWindow','height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');">
</div>
</body>
agents.php
...
<?php
while($row = mysql_fetch_array( $result ) ) {
?>
<tr bgcolor="#CCCCFF">
<td><?php echo $row['agentNo']; ?></td>
<td><?php echo $row['agent']; ?></td>
<td><?php echo $row['branch']; ?></td>
<td><?php echo $row['region']; ?></td>
<td><a href="javascript: if(confirm('Select Agent?')) {window.top.opener.location ='client_details.php?agentid=<?php echo $row["agentID"]; ?>';window.top.close();}">Select</a></td>
</tr>
<?php
}
?>
</table>
<?php
}
?>
...
Now the problem is that in the popup child window agents.php, when i click the Select link and closes the popup window it retrieves the firstName & lastName variables and stores them in the agents textboxes in client_details.php but then reloads the parent page(client_details.php) and automatically resets all previous textfields. What i want to do is to retrieve the database variables and populate them in client_details.php without reloading the page when the child window(agents.php) select link is clicked.
I think AJAX will do the trick but i don't know how. Please help. Thanx in advance.