I am trying to pass 2 variables from PHP to JavaScript and the vice versa.
I understand how to pass one variable, and it's okay, but when I tried to pass 2 variales, one of them passed, the other one didn't work.
Here is the code:
(1) file1.php:
<script type="text/javascript">
var id = <?php echo $id ; ?>
var q= <?php echo $q ; ?>
</script>
<script type="text/javascript"src="http://localhost/site/js/java.js"> </script>
(2) Java.js:
http://localhost/site/file2.php?id="+id +"&q="+q
(3) file2.php:
$id = $_GET['id']; >> it works fine
$q= $_GET['q']; >> doesn't pass (error: undefined)
I am not sure where the problem is, I just think it's in the number (2) step.
Any help will be appreciated.
Java.jsdid you just...var q=is set and is not null. have you looked athttp://localhost/site/file2.php?id="+id +"&q="+qafter it was parsed to make sure that theqvalue is not empty?&q=undefinedand you will have undefined in php.