Jump to content

Archived

This topic is now archived and is closed to further replies.

theITvideos

How to Pass Simple PHP variable to jQuery

Recommended Posts

Hi there,

 

I am working on a php web form.

 

I have a variable named $isFruit having value of 1

 

When I do a:

 

print_r($isFruit)

 

It gives me value as 1, which is good.

 

Now I need to pass this php variable into a jquery function:

 

$('document').ready(function() {         
  //I need to get the value of $isFruit variable here
}

 

How can pass the php variable into this function.

 

Kindly reply.

 

All comments and feedbacks are always welcomed.

 

Thank you! :)

Share this post


Link to post
Share on other sites

<?php $isFruit = "some var"; ?>
<script type="text/javascript">
$(function() {
    alert("<?php echo $isFruit; ?>");
}
</script>

 

Should do the trick.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.