is there any way to pass a variable from php into a variable in javascript? or do I need to revert to AJAX to get this done?
GraficRegret
0
Junior Poster
Recommended Answers
Jump to PostI'm assuming you mean javascript and not java. No need for ajax. Something as simple as this:
<script> var myVar = '<?php echo $myvar;?>'; //rest of code </script>
Jump to PostExactly the same:
function myFunc('<?php echo $myvar;?>'){ var secondVar = '<?php echo $myvar2;?>'; }
However, I assume that a js variable would be passed to the function as a parameter, so it would be best to apply the php value to the var instead.
What you …
All 6 Replies
diafol
GraficRegret
0
Junior Poster
diafol
GraficRegret
0
Junior Poster
GraficRegret
0
Junior Poster
diafol
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.