[jQuery] Pop-up window problem (jQuery 1.2.6)
I'm trying to populate a pop-up window with the form values of the
main window. Unfortunately, I keep getting a 'Element referenced by
ID/NAME in the global scope. Use W3C standard document.getElementById
() instead.' error, on both lines 21 and 22. I tried using non-jQuery
methods, and it appears that there's a runtime issue. The div I'm
trying to inject the form values into in the pop-up page doesn't seem
to be available to me when the function fires. Instead, the alerts I
put in for debugging keep telling me it's null/undefined. Here's my
code, so you can see what's going on:
jsform.html (main page):
<html>
<head>
<title>blah</title>
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></
script>
<script type="text/javascript">
$(document).ready(function()
{
$("#preview").click(function()
{
var popup = window.open('newspreview.html',
'Preview_Entry');
var results = popup.document.getElementById('results');
var popupBody = popup.document.getElementsByTagName('body')
[0];
//var results = popupBody.getElementsByTagName('div')[0];
//var results = popup.document.getElementsByTagName('div')
[0];
alert("Pop-up: " + popup);
alert("popup.document: " + popup.document);
alert("popup <body>: " + popupBody);
alert("Results: " + results);
alert("Author name: " + myForm.elements
['cf_author'].value); // <-- line 21
results.innerHTML = "Author name: " + myForm.elements
["cf_author"].value + "<br />"; // <-- line 22
});
});
/* window.onload = function()
{
var myForm = document.forms["myForm"];
var formPreview = document.getElementById('preview');
var formSubmit = document.getElementById('submit');
formPreview.onclick = function()
{
var popup = window.open('newspreview.html',
'Preview_Entry');
//var results = popup.document.getElementById('results');
var popupBody = popup.document.getElementsByTagName('body')
[0];
var results = popupBody.getElementsByTagName('div')[0];
//var results = popup.document.getElementsByTagName('div')
[0];
alert("Pop-up: " + popup);
alert("popup.document: " + popup.document);
alert("popup <body>: " + popupBody);
alert("Results: " + results);
alert("Author name: " + myForm.elements
['cf_author'].value);
results.innerHTML = "Author name: " + myForm.elements
["cf_author"].value + "<br />";
}
formSubmit.onclick = function()
{
myForm.action = "news.submit.php";
myForm.submit();
}
} */
</script>
</head>
<body>
<form name="myForm" method="post">
<input type="text" name="cf_title" value="Enter news-post
title!" /><br /><br />
<input type="text" name="cf_author" value="Author name!" /><br /