script not reloading page properly
Posted: Wed Feb 23, 2011 11:52 pm
I have included in my php a bit of javascript, which I am usually fairly confident with. I am having a strange issue, though. I have included my document, and would appreciate any advice to get this working properly.
My dilemma is that once the "reload" function runs, window.location should reload the page with values appended to the address, but it simply refreshes. I added a popup window AFTER window.location, and when the window opens, then everything works as it should!?!
Again, any advice is greatly appreciated!
-Shane
My dilemma is that once the "reload" function runs, window.location should reload the page with values appended to the address, but it simply refreshes. I added a popup window AFTER window.location, and when the window opens, then everything works as it should!?!
Again, any advice is greatly appreciated!
-Shane
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>String Compare</title>
<script type="text/javascript">
function reload()
{
var string1 = document.getElementById("string1").value;
var string2 = document.getElementById("string2").value;
window.location="4StringCompare.php?string1=" + string1 + "&string2=" + string2;
//window.alert("TEST");
}
</script>
</head>
<body>
<form onSubmit="reload()">
<table><tr><td>
<input type="text" id="string1"/>
</td></tr><tr><td>
<input type="text" id="string2"/>
</td></tr></table>
<input type="submit" value="Compare strings"/>
</form>
<?php
$string1 = $_GET["string1"];
$string2 = $_GET["string2"];
if (empty($string1) && empty($string2))
echo "Both strings are empty";
elseif (empty($string1))
echo "String 1 is empty";
elseif (empty($string2))
echo "string 2 is empty";
else
{
if (substr_compare($string1,$string2,0))
echo "\"$string1\" and \"$string2\" are not identical strings.";
else
echo "\"$string1\" and \"$string2\" are identical strings.";
}
?>
</body>
</html>