PHP – Pass an array parameter to Javascript Function

Writing an PHP array in a javascript file with json_encode.

Code Example:

<script type="text/javascript">
    document.getElementByID('submitButton').onclick = function() {
        var books = <?php echo json_encode($books); ?>;
<input type="submit" value="Submit" id="submitButton">

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *