Jump to content

How to use php data in javascript


sandeepm

Recommended Posts

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

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
×
×
  • Create New...