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">

URL: http://stackoverflow.com/questions/6502107/how-to-pass-php-array-parameter-to-javascript-function/6502154#6502154

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.