Javascript problem with form submission on Seamonkey

D

Daniel Rudy

Consider the following code:

<?php

if (isset($_POST['width']) && isset($_POST['height']))
{
// output the geometry variables
print "Window width is: ". $_POST['width'] ."<br>\n";
print "Window height is: ". $_POST['height'] ."<br>\n";
}
else
{
print <<<HTMLBLOCK
<form name="screensize" method="POST" action="$_SERVER[PHP_SELF]">
<input type="hidden" name="width" value="">
<input type="hidden" name="height" value="">
</form>

<script language="javascript">
var myform = document.screensize;
myform.width.value = screen.width;
myform.height.value = screen.height;
myform.submit();
</script>

HTMLBLOCK;
}

?>

This code renders as the following in a web browser:

<form name="screensize" method="POST" action="/test/test.php">
<input type="hidden" name="width" value="">
<input type="hidden" name="height" value="">
</form>

<script language="javascript">
var myform = document.screensize;
myform.width.value = screen.width; <-- Line 8
myform.height.value = screen.height;
myform.submit();
</script>


Here's the problem. In IE7, this works just fine. But in Seamonkey
1.1.8, it fails (blank page). The error console gives the following
error: myform has ho properties (line 8). I haven't tried it in other
browsers. I have exhausted my reference documentation, and I couldn't
find an answer on Google either. Everything I found says this should
work, but it's not. Any ideas?
 
J

Jonathan N. Little

Daniel said:
Consider the following code:

<?php

if (isset($_POST['width']) && isset($_POST['height']))
{
// output the geometry variables
print "Window width is: ". $_POST['width'] ."<br>\n";
print "Window height is: ". $_POST['height'] ."<br>\n";
}
else
{
print <<<HTMLBLOCK
<form name="screensize" method="POST" action="$_SERVER[PHP_SELF]">
<input type="hidden" name="width" value="">
<input type="hidden" name="height" value="">
</form>

<script language="javascript">
var myform = document.screensize;
myform.width.value = screen.width;
myform.height.value = screen.height;
myform.submit();
</script>

HTMLBLOCK;
}

?>

This code renders as the following in a web browser:

<form name="screensize" method="POST" action="/test/test.php">
<input type="hidden" name="width" value="">
<input type="hidden" name="height" value="">
</form>

<script language="javascript">
var myform = document.screensize;
myform.width.value = screen.width; <-- Line 8
myform.height.value = screen.height;
myform.submit();
</script>


Here's the problem. In IE7, this works just fine. But in Seamonkey
1.1.8, it fails (blank page). The error console gives the following
error: myform has ho properties (line 8). I haven't tried it in other
browsers. I have exhausted my reference documentation, and I couldn't
find an answer on Google either. Everything I found says this should
work, but it's not. Any ideas?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-language" content="en-us">
<title>What document.screensize?</title>

<script type="text/javascript">
function getObj(){
var doc = document;
var dump = doc.getElementById('dump');
for (var obj in doc) {
var clone=dump.cloneNode(true);
clone.firstChild.nodeValue=obj;
doc.body.appendChild(clone);
}
}
</script>

</head>
<body onload="getObj()">
<h1>What document.screensize?</h1>
<div id="dump">Objects in document collection:</div>
</body>
</html>
 
D

Daniel Rudy

At about the time of 4/28/2008 8:58 AM, Jonathan N. Little stated the
following:
Daniel said:
Consider the following code:

<?php

if (isset($_POST['width']) && isset($_POST['height']))
{
// output the geometry variables
print "Window width is: ". $_POST['width'] ."<br>\n";
print "Window height is: ". $_POST['height'] ."<br>\n";
}
else
{
print <<<HTMLBLOCK
<form name="screensize" method="POST" action="$_SERVER[PHP_SELF]">
<input type="hidden" name="width" value="">
<input type="hidden" name="height" value="">
</form>

<script language="javascript">
var myform = document.screensize;
myform.width.value = screen.width;
myform.height.value = screen.height;
myform.submit();
</script>

HTMLBLOCK;
}

?>

This code renders as the following in a web browser:

<form name="screensize" method="POST" action="/test/test.php">
<input type="hidden" name="width" value="">
<input type="hidden" name="height" value="">
</form>

<script language="javascript">
var myform = document.screensize;
myform.width.value = screen.width; <-- Line 8
myform.height.value = screen.height;
myform.submit();
</script>


Here's the problem. In IE7, this works just fine. But in Seamonkey
1.1.8, it fails (blank page). The error console gives the following
error: myform has ho properties (line 8). I haven't tried it in other
browsers. I have exhausted my reference documentation, and I couldn't
find an answer on Google either. Everything I found says this should
work, but it's not. Any ideas?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-language" content="en-us">
<title>What document.screensize?</title>

<script type="text/javascript">
function getObj(){
var doc = document;
var dump = doc.getElementById('dump');
for (var obj in doc) {
var clone=dump.cloneNode(true);
clone.firstChild.nodeValue=obj;
doc.body.appendChild(clone);
}
}
</script>

</head>
<body onload="getObj()">
<h1>What document.screensize?</h1>
<div id="dump">Objects in document collection:</div>
</body>
</html>

That actually works in both. I did yet another modification and I got
it to work. So now I can get JavaScript variables to PHP using the POST
method instead of the GET method that I have found all over the web.
Here's the resulting code:


<?php

if (isset($_POST['width']) && isset($_POST['height']))
{
$width = $_POST['width'];
$height = $_POST['height'];
print <<<HTMLBLOCK
<html>
<head>
<title>Javascript Variable to PHP Variable Test</title>
</head>
<body>
Window Width: $width<br>
Window Height: $height<br>
</body>
</html>

HTMLBLOCK;
}
else
{
print <<<HTMLBLOCK
<html>
<head>
<title>Javascript Variable to PHP Variable Test</title>
<script language="javascript">
function submitScreen()
{
form = document.getElementById("formSCR");
form.width.value = screen.width;
form.height.value = screen.height;
form.submit();
}
</script>
</head>
<body onload="submitScreen()">
<form id="formSCR" method="POST" action="$_SERVER[PHP_SELF]">
<input type="hidden" name="width" value="" id="width">
<input type="hidden" name="height" value="" id="height">
</form>
</body>
</html>

HTMLBLOCK;
}

?>

The other issue that I found was in the getElementById function.
Javascript is alot like C, and so is PHP for that matter, but being case
sensitive is a factor. I kept wondering why getElementByID would never
work (It would say that it wasn't a function, which is correct).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,516
Members
44,985
Latest member
rsts

Latest Threads

Top