sandeepm Posted February 11, 2017 Share Posted February 11, 2017 function test(){ var a = "hellow"; } This is my javascript function i want to use my php data to this function, how? Link to comment Share on other sites More sharing options...
dsonesuk Posted February 11, 2017 Share Posted February 11, 2017 echo php variable where "hellow" is, is the simple option, <?php $phpvaraiable ="hellow"; ?> <script> function test(){ var a ="<?php echo $phpvaraiable; ?>"; alert(a); } </script> The other would require you use AJAX if the php data is required after the initial page load and the user has to make a choice before specific required data is retrieved, and you don't want cause another page load to retrieve this specific data. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now