MikeBronner
Programmer
Hi All!
I'm hoping someone can help me with the following code:
The problem here is that the onclick on works as long as the window that created the row in the parent page is open. As soon as I close the popup, the onclick no longer functions. Any ideas on how I can get this to work?
I've been toying with some general code, but haven't got it to work either. This code is on the main page, where the script from the popup (above code) inserts the row:
I know that the reason this generic code isn't working is because childNodes[] is an array that requires the index to be specified. Unfortunately I don't know how to work around that at this point.
Thanks for all your help!
I'll post my complete code, if that will help.
Main Page:
Popup Page:
Take Care,
Mike
I'm hoping someone can help me with the following code:
Code:
var o_doc = opener.document;
var o_row = null;
var o_cell_name = o_doc.createElement("td");
var o_cell_phone = o_doc.createElement("td");
var o_cell_zip = o_doc.createElement("td");
if (o_doc.getElementById("<?= $_GET['id'] ?>")) {o_row = o_doc.getElementById("<?= $_GET['id'] ?>");}
else {o_row = o_doc.createElement("tr");}
o_cell_name.innerHTML = "<?= $_POST['name'] ?>";
o_cell_phone.innerHTML = "<?= $_POST['phone'] ?>";
o_cell_zip.innerHTML = "<?= $_POST['zip'] ?>";
o_row.appendChild(o_cell_name);
o_row.appendChild(o_cell_phone);
o_row.appendChild(o_cell_zip);
o_row.setAttribute("id", "<?= $_GET['id'] + 1 ?>");
o_row.onclick = function() {opener.open('popup.php?id=<?= $_GET['id'] + 1 ?>', '', '');};
o_doc.getElementById("list").tBodies[0].appendChild(o_row);
window.close();
The problem here is that the onclick on works as long as the window that created the row in the parent page is open. As soon as I close the popup, the onclick no longer functions. Any ideas on how I can get this to work?
I've been toying with some general code, but haven't got it to work either. This code is on the main page, where the script from the popup (above code) inserts the row:
Code:
document.getElementById("list").tBodies[0].childNodes.onclick = function()
{
window.open('popup.php?id=' + this.getAttribute("id") +, '', '');
}
I know that the reason this generic code isn't working is because childNodes[] is an array that requires the index to be specified. Unfortunately I don't know how to work around that at this point.
Thanks for all your help!
I'll post my complete code, if that will help.
Main Page:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
document.getElementById("list").tBodies[0].childNodes.onclick = function()
{
window.open('popup.php?id=' + this.getAttribute("id") +, '', '');
}
</script>
</head>
<body>
<table id="list" border="1">
<thead>
<tr>
<th colspan="3" onclick="window.open('popup.php?id=0', '', '');" style="cursor: pointer;">List</th>
</tr>
<tr>
<th>Name</th>
<th>Phone</th>
<th>ZIP</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
Popup Page:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
<?php
if ($_POST['action'] == 'save')
{
?>
var o_doc = opener.document;
var o_row = null;
var o_cell_name = o_doc.createElement("td");
var o_cell_phone = o_doc.createElement("td");
var o_cell_zip = o_doc.createElement("td");
if (o_doc.getElementById("<?= $_GET['id'] ?>")) {o_row = o_doc.getElementById("<?= $_GET['id'] ?>");}
else {o_row = o_doc.createElement("tr");}
o_cell_name.innerHTML = "<?= $_POST['name'] ?>";
o_cell_phone.innerHTML = "<?= $_POST['phone'] ?>";
o_cell_zip.innerHTML = "<?= $_POST['zip'] ?>";
o_row.appendChild(o_cell_name);
o_row.appendChild(o_cell_phone);
o_row.appendChild(o_cell_zip);
o_row.setAttribute("id", "<?= $_GET['id'] + 1 ?>");
// o_row.onclick = function() {opener.open('popup.php?id=<?= $_GET['id'] + 1 ?>', '', '');};
o_doc.getElementById("list").tBodies[0].appendChild(o_row);
window.close();
<?php
}
?>
</script>
</head>
<body>
<form method="post" action="?id=<?= $_GET['id'] ?>">
<input type="hidden" name="action" id="action" value="" />
<table>
<tr>
<td>Name:</td>
<td><input type="text" id="name" name="name" /></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" id="phone" name="phone" /></td>
</tr>
<tr>
<td>ZIP:</td>
<td><input type="text" id="zip" name="zip" /></td>
</tr>
<tr>
<td colspan="2"><input type="button" value="Save" onclick="document.getElementById('action').value = 'save';this.form.submit();" /></td>
</tr>
</table>
</form>
</body>
</html>
Take Care,
Mike