Saturday 31 August 2013

Unhandled Error: Cannot convert 'document.getElementById(punkte_liste_titel_user)' to object

Unhandled Error: Cannot convert
'document.getElementById(punkte_liste_titel_user)' to object

I have a html page (partly generated with PHP), and I have a JavaScript
file included at the bottom of the page that provides some onclick
functions. I was struggling to get the variables from PHP to JS, so I
created two <span>s with unique ids and put the content of the variables
there (numeric/int values). My idea was to use var php_get_userid =
document.getElementById(punkte_liste_titel_user).innerHTML; to have JS
read the values into variables, and then use them. However the
getElementById doesn't work although the <span> with the corresponding ID
definitly does exist. In Opera it says
Unhandled Error: Cannot convert
'document.getElementById(punkte_liste_titel_user)' to object
Chrome says
Uncaught TypeError: Cannot read property 'innerHTML' of null
The HTML of the area looks like this
<body>
<div id="wrapper">
<div id="punkte_liste_titel">
Points <span id="punkte_liste_titel_datum">20130901</span>/<span
id="punkte_liste_titel_user">3</span>
</div> <!-- Ende Punkteliste -->
<div id="punkte_liste">
...
the JS starts like this
$('.punkte_kategorie_element').click(function() {
var php_get_userid =
document.getElementById(punkte_liste_titel_user).innerHTML;
var php_get_datum =
document.getElementById(punkte_liste_titel_datum).innerHTML;
...
the JavaScript file is included right before the </body> tag
I tried to create a minimal version of this at
http://jsfiddle.net/WRfh5/2/ which doesn't run either... what am I
missing?

No comments:

Post a Comment