2

Using this StackOverflow Question/Answer, I have a Tooltip Javascript that is supposed to use a PHP echo of a session variable. Instead of actually writing out the value, it is writing out the variable name, myvar?

I tried to \ the echo statement where ' occur with no luck.

Here is the code in question and screenshot of what I'm getting on mouseover:

var ddimgtooltip={

    tiparray:function(){
        var tooltips=[]
        var myvar='<?php echo($row_WADAHTG_ScheduleRequest[\'EmNo\']); ?>';
        tooltips[0]=["image/emp/$myvar.bmp", "$myvar", {background:"#DDECFF", width:"200px"}]
        return tooltips //do not remove/change this line
    }(),

enter image description here

Rocco The Taco
  • 3,695
  • 13
  • 46
  • 79
  • echo it, just like the line above it. – Martijn Feb 26 '18 at 15:53
  • 1
    Possible duplicate of [How can I do string interpolation in JavaScript?](https://stackoverflow.com/questions/1408289/how-can-i-do-string-interpolation-in-javascript) – kamoroso94 Feb 26 '18 at 15:59
  • Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Rotimi Feb 26 '18 at 16:11

2 Answers2

3

try tho change this:

var myvar='<?php echo($row_WADAHTG_ScheduleRequest[\'EmNo\']); ?>';
tooltips[0]=["image/emp/$myvar.bmp", "$myvar", {background:"#DDECFF", width:"200px"}]

to this:

var myvar='<?php echo($row_WADAHTG_ScheduleRequest[\'EmNo\']); ?>';
tooltips[0]=["image/emp/" + myvar + ".bmp", myvar, {background:"#DDECFF", width:"200px"}]

you have already your php value into myvar so you don't need to use $myvar as in php but only myvar for javascript

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
1

try:

var myvar='<?php echo($row_WADAHTG_ScheduleRequest[\'EmNo\']); ?>';
tooltips[0]=["image/emp/" + myvar + ".bmp", myvar, {background:"#DDECFF", width:"200px"}]
Lee
  • 418
  • 2
  • 8