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,179
  • 17
  • 79
  • 177

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
  • 31,821
  • 17
  • 84
  • 96
-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
  • 796
  • 5
  • 14