I am trying to pass a php variable inside javascript bt it is not working.
<a href="javascript:wait1();getPass('<?php echo $current?>');">Comment</a>
Is it possible to do so or I may be incorrect somewhere…
Thanks for your response in advance! 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re dynamically generating Javascript. You will save yourself some headaches if when you need to do this you, keep it simple. Transfer the data from PHP to Javascript in the simplest way possible at the top of the page:
As others have pointed out, you will want to encode and quote your php variable, using
json_encode(in which case you probably won’t need the quotes), or a simpler escape function if you know the possible values.Now, your inline code can be simpler:
A final recommendation would be to pull this out into its own function, and use the “onclick” attribute.