I'm trying to implement the following functionality into the file test.php:

When I scroll down the page and then hit a button, the page should remember
the scrolled position, refresh the page and then scroll down to the
remembered position. I've almost managed to make this work, but only almost.

The first time I click one of the buttons, the page won't scroll, but after
that it works fine. I think the reason for this is that the function
hentKoordinat() gets called before $teller is set. hentKoordinat() uses
$teller.

Anyone know a way to make this work?

Thanks alot!

Lars


File test.php:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd";>
<html>
<head>
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
<!--

function getPageScroll(){
    var X, Y;
    if(typeof window.pageXOffset == 'number'){
        X = window.pageXOffset;
        Y = window.pageYOffset;
    }else{
        if((window.document.compatMode)&&
                  (window.document.compatMode == 'CSS1Compat')){
            X = window.document.documentElement.scrollLeft;
            Y = window.document.documentElement.scrollTop;
        }else{
            X = window.document.body.scrollLeft;
            Y = window.document.body.scrollTop;
        }
    }
    return {scrollX:X,scrollY:Y};
}
function hentKoordinat()
{
<?php
 //*****Here the problem arises. The first time you click a button $teller
is not set.*****
document.form<?php echo $teller; ?>.yKoord.value = getPageScroll().scrollY
}
function mScroll() {
 <?php if(!isset($yKoord)) $yKoord=0; ?>
 <?php if($yKoord=='') $yKoord=0; ?>
 self.scrollTo(0,<?php echo $yKoord; ?>)
}

//-->
</script>
</head>

<body onLoad="mScroll()">
<?php echo "<p> Ykoordinat: " . $yKoord . "<p>";
echo "Teller: " . $teller;

for($i=0; $i<150; $i++) {
 echo '<br>';
}
for($teller=0; $teller<2; $teller++) {
?>
 <form action="test.php" name="form<?php echo $teller; ?>" onsubmit="return
hentKoordinat()">
  <input type="hidden" name="teller" value="<?php echo $teller; ?>">
  <input type="hidden" name="yKoord">
  <input name="button1" type="submit" value="Send input">
 </form>
 <?php $teller++; ?>
<?php
} //for($teller=0; $i<2; $i++) {
?>
</body>
</html>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to