I.ve this thing in php
$v = "test";
How do i pass this to javascript
I did like this
<script>
var t = <?php echo $v; ?>
</script>
I'm passing that t to URL But ii says undefined
I.ve this thing in php
$v = "test";
How do i pass this to javascript
I did like this
<script>
var t = <?php echo $v; ?>
</script>
I'm passing that t to URL But ii says undefined
If you look at the source of the page in your browser (with your first attempt), you see:
<script>
var t = test
</script>
And from here, you could guess what's amiss.
<script>
var t = "<?php echo $v; ?>";
</script>
<?php
echo "<script type='text/javascript'>var t = '$v';</script>";
?>
Javascript runs clientside and php runs server side so you can't just pass one straight through to the other - they don't run at the same time. You can use php to create javascript to run later though.