Pass PHP array parameter to Javascript Function

/ Published in: PHP
Save to your folder(s)

Writing an PHP array in a javascript file with json_encode.

Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. document.getElementByID('submitButton').onclick = function() {
  3. var movies = <?php echo json_encode($movies); ?>;
  4. showMovies(movies);
  5. };
  6. </script>
  7. ...
  8. <input type="submit" value="Test JavaScript" id="submitButton">


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.