SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Jun 2, 2005, 13:36 #1
- Join Date
- Sep 2004
- Location
- Boston
- Posts
- 174
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Interwindow Communication - How to open an "edit this field" window?
Hi Folks,
Could someone explain the basics behind opening a new browser window and passing information between the parent and the child windows? Here's what I want to do:
* Display a list of records
* click on a specific record to open an edit window with a form for changing record values.
* click on "submit" in the form window to save the data, close the child window, and refresh the main list of records in the original window. If it didn't refresh the main record list that would be workable too.
I have no problems with all the coding stuff, I just don't know how the window communication works.
How does phpmyadmin do it with the separate SQL window?
Thanks in advance,
--Mark
-
Jun 2, 2005, 14:18 #2
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
JavaScript. Your new window can access the one that opened it through window.opener.
Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Jun 2, 2005, 14:22 #3
- Join Date
- Aug 2004
- Location
- England, UK
- Posts
- 249
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Someone move this to the JavaScript forum.
Basically you're gonna need to use JavaScript as opening/closing windows is client-side and thus you use that. When you loop through, printing the rows you will print the primary key of the record into the javascript code so that the script in the newly identified window can edit the correct record. Here's an example code:
list_records.php
PHP Code:<script type="text/javascript">
<!--
function editRecord( id )
{
credentials = "width=400,height=400,left=190"; // Look this up for correct syntax
window.open( "edit_record.php?id="+id, "edit"+id, credentials );
}
//-->
</script>
<table>
<?php
while ( $r = mysql_fetch_array( $result ) )
{
?>
<tr>
<td><?php print $r["id"]; ?></td>
<td><?php print $r["title"]; ?></td>
<td><a href="javascript: editRecord(<?php print $r["id"]; ?>);">Edit</a></td>
<tr>
<?php
}
?>
</table>
PHP Code:<?php
if ( $_SERVER["REQUEST_METHOD"] != "POST" )
{
// select the record from the database according to $_GET["id"]
// then populate a form with it ready for editing
?>
<form method="post" act="edit_record.php">
<!-- stuff here -->
<input type="submit" value="Submit" />
</form>
<?php
}
else
{
// save record here according to $_POSTed variables
?>
<script type="text/javascript">
<!--
opener.location.reload(); // will refresh the parent window so that data is updated in it
window.close(); // closes the popup
//-->
</script>
<?php
}
?>
(wow can't believe I bothered to do all that)michael.Crabbe
-
Jun 2, 2005, 20:04 #4
- Join Date
- Sep 2004
- Location
- Boston
- Posts
- 174
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you, Michael, that's exactly what I was looking for... opener.location.reload(). I'll give that a shot.
Bookmarks