0

Can't get the php variables to populate the javascript code

I tried the code below.

<?php
$destination="PAR";
$destination_name="Paris";
?>
<script async src="//www.travelpayouts.com/weedle/widget.js?
width=260px&marker=235474&host=search.jetradar.com&locale=en&currency=
usd&powered_by=false&destination="<?php echo $destination ? 
>";&destination_name="<?php echo $destination_name ?>";" 
charset="UTF-8"></script>

The result doesn't show the right destination

  • did you try escaping the double quotes or replacing them with single quotes? – gianni Jul 07 '19 at 19:52
  • Possible duplicate of [How to pass variables and data from PHP to JavaScript?](https://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript) – Dharman Jul 07 '19 at 23:09

1 Answers1

0

You don't need quotes around GET parameters.

<?php
$destination="PAR";
$destination_name="Paris";
?>
<script async src="//www.travelpayouts.com/weedle/widget.js?
width=260px&marker=235474&host=search.jetradar.com&locale=en&currency=
usd&powered_by=false&destination=<?php echo $destination ?>&destination_name=<?php echo $destination_name ?>" 
charset="UTF-8"></script>
Fred
  • 868
  • 10
  • 22