Posted By

Narayon on 03/10/12


Tagged

javascript php array json


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

guillermoj88gmailcom


Pass PHP array parameter to Javascript Function


 / Published in: PHP
 

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

Writing an PHP array in a javascript file with json_encode.

  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  

You need to login to post a comment.