Vidya_tr Posted April 4, 2009 Share Posted April 4, 2009 Can I pass a variable declared in php to a function written in javascript?? Link to comment https://forums.phpfreaks.com/topic/152533-doubt-on-values-of-variables-passed-to-a-function/ Share on other sites More sharing options...
Fruct0se Posted April 4, 2009 Share Posted April 4, 2009 You can only do this if the php is run prior to your javascript code, you could echo the variable to an input field then retrieve it using javascript. So you could <?php echo '<input type="hidden" name="javavariable" value="'.$yourvariable.'">'; ?> Then in javascript use myvar = document.getElementById("javavariable").value; Hope this helps. Link to comment https://forums.phpfreaks.com/topic/152533-doubt-on-values-of-variables-passed-to-a-function/#findComment-801149 Share on other sites More sharing options...
student101 Posted April 4, 2009 Share Posted April 4, 2009 <?php $user_id = $_GET["uid"]; ?> <script type="text/javascript"> var user_id = <?php echo($user_id);?> ; alert("Your user ID is:" + user_id); </script> Source: G-o-o-g-l-e Link to comment https://forums.phpfreaks.com/topic/152533-doubt-on-values-of-variables-passed-to-a-function/#findComment-801151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.