sandeepm

How to use php data in javascript

2 posts in this topic

function test(){
var a = "hellow";
}

This is my javascript function i want to use my php data to this function, how?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now