i want to do something like this how do you do it?

<?php
$meat="cow";
<script type="text/javascript">
document.write($meat);
</script>
?>

Recommended Answers

All 2 Replies

hi just add another variable on the js which contain the php variable like this

<?php
$meat="cow";

?>
<script type="text/javascript">
var meat="<?php echo $meat; ?>";
document.write(meat);
</script>

Sorry I know this topic is 2 months old but this might help someone. Always encode JS variables with JSON when creating a JS variable from a PHP variable. See below:

instead of: var meat="<?php echo $meat; ?>";

do this: var meat="<?php echo json_encode($meat); ?>";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.