Computer Hope
Internet & Networking => Web design => Topic started by: newfunland on November 07, 2017, 12:02:52 PM
-
hi guys been searching for the past couple day trying to figure out whats wrong, if i stick this line of code anywhere outside of the html im running it works fine the variable is set to what it was expected to
var userID = <?php echo ($stats['displayname']); ?>
but if i stick it inside my code like below i get an error of Uncaught SyntaxError: Unexpected token var
script>
var userID = <?php echo ($stats['displayname']); ?>
var gamescore = new score.Submit(publicsitekey, teamName , userID{
})
</script>
when viewing the page pages html after running it looks like this
var userID = Marmalade var gamescore = new Score.Submit('8VDCBKu05bEAHebtB0pgqWdcEB60B5kA', 'RedTeam', userID{
})
i sure it a syntax issue where i forgot something in the var, or its not breaking and not reading a new line. but i cant figure it out for the life of me, any help is appreciated, or just the most simple easiest way to set an html var from a php var, without the user having to do anything, i have also tried adding a ; after ?> but it just add ; to the user display name
-
var userID = Marmalade
First problem is the lack of a semicolon to terminate the statement. The var afterwards makes no sense to the interpreter because of this, particularly as there is no newline.
But that isn't the only issue. The statement would assign the variable userID to the value of the *variable* Marmalade. I'm going to presume that you want to set the value of userID to the String "Marmalade" here? In that case you need quotes:
var userID = "<?php echo ($stats['displayname']); ?>";
-
thanks for they reply, and info. yes that is what i was trying to do, and it is working, that seems to be my biggest problem is when and where to use certain things.