Is it possible to pass a php variable inside javascript? -


i trying pass php variable inside javascript bt not working.

<a href="javascript:wait1();getpass('<?php echo $current?>');">comment</a> 

is possible or may incorrect somewhere...

thanks response in advance! :)

you're dynamically generating javascript. save headaches if when need you, keep simple. transfer data php javascript in simplest way possible @ top of page:

<script type="text/javascript" > var $current = '<%? echo $current; %>'; </script> 

as others have pointed out, want encode , quote php variable, using json_encode (in case won't need quotes), or simpler escape function if know possible values.

now, inline code can simpler:

<a href="javascript:wait1();getpass($current);">comment</a> 

a final recommendation pull out own function, , use "onclick" attribute.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -