I am working on a page that is basically a long form, with tables of info followed by a submit button after each table.
The form submits to itself and changes the info in the tables based on user input.
What I would like to do is have the page jump to "Section X" if "Submit Button X" is pressed, jump to "Section Y" if "Submit Button Y" is pressed, etc.
I'm currently using this Javascript in the head of the doc to try and accomplish this:
<script type="text/javascript">
var anchors = new Array(
<?php
for($i = 0; $i < 13; $i++) {
$anchors = "\"$divTag[$i]\"";
if($i < 12) {
$anchors .= ", ";
}
echo $anchors;
} ?>
)
function jumpToAnchor() {
<?php if(isset($_POST["submit_fjw"])) { ?>
window.location = String(window.location).replace(/\#.*$/, "") +
"#" + anchors[0];
<?php } if(isset($_POST["submit_jwl"])) { ?>
window.location = String(window.location).replace(/\#.*$/, "") +
"#" + anchors[1];
<?php } ?>
}
It works... kinda. It doesn't jump on the first press of the Submit button, but the second.
I'm open to suggestions... less javascript is better, because my javascript skills are weak at best. Could I use a variable tied to the submit button that will pass a value to the PHP script and correctly jump to the right section?