Tell Javascript What Form Has Called it in a PHP file
Posted: Thu Jul 13, 2006 7:58 pm
I have the following code that preserves the location of the scroll bar after a submit... Now here is the problem, I am not very good at javascript to be honest!
I just want the "function saveScrollCoordinates()" to know which form has called it! what can I put in document.form1.scrolly.value instead of form1 some sort of varaible passed through parameters etc or whatever way... if you run the code you will notice that only the first submit button works but not the second.... Summing it up: "Just need to know how to tell the document.form1.scrolly.value" which form has called it instead of hard wiring the form name.
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Scroll</title>
<script language=javascript>
function saveScrollCoordinates() {
document.form1.scrolly.value = (document.all)?document.body.scrollTop:window.pageYOffset;
}
</script>
</head>
<body onLoad="javascript:window.scrollTo(0,[php]<?php echo $_POST['scrolly']; ?>[/php])">
<form name="saveCoords">
</form>
<form name="form1" id="form1" onSubmit='saveScrollCoordinates()' method="POST">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>
<input type="hidden" name="scrolly" value="">
<input name="" type="submit" value="Submit" />
</p>
</form>
<form name="form2" id="form2" onSubmit='saveScrollCoordinates()' method="post">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>
<input type="hidden" name="scrolly" value="">
<input name="" type="submit" value="Submit" />
</p>
</form>
</body></html>