1

i am using this:

$newPostID_fromCookie = $_COOKIE['scrollToBottom']+5000;
echo "
  <script>
  window.onload = function () {
    //document.getElementById('$newPostID_fromCookie').scrollIntoView();
    alert('$newPostID_fromCookie');
  }
  </script>
";

This correctly shows the value from the cookie in the alert, but i am getting 'is null' error when trying to use the value in the getElementById.

How can i use the value in this?

Lovelock
  • 7,689
  • 19
  • 86
  • 186

2 Answers2

0

Your $newPostID_fromCookie seems to be an integer. In xHTML, this is not valid and maybe your browser does not like it. You should use a string (with a prefix for example):

document.getElementById('cookie_$newPostID_fromCookie').scrollIntoView();

Of course, change your HTML in consequence.

Community
  • 1
  • 1
Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
-1

The getElementById() does a DOM lookup and returns the first element with the specified id. In this case $newPostID_fromCookie should be an id of an existing element in the DOM.

hutchbat
  • 806
  • 6
  • 14