jQuery global array showing as undefined

by Charles Wilkins IV   Last Updated May 07, 2019 18:10 PM

I have set a couple of global variables on page load as follows:

jQuery(document).ready(function() {
    console.log("Onload PHP vis_options:"+JSON.stringify(<?php echo 
    json_encode($vis_options); ?>)+"\r\n");
    var vis_options = <?php echo json_encode($vis_options); ?>;
    var home_options = <?php echo json_encode($home_options); ?>;
    console.log("Onchange PHP vis_options:"+JSON.stringify(vis_options)+"\r\n");
    var ind_pts_game = Number(jQuery("#ind_pts_game").val());

    jQuery(document.body).on("change", '#bowl1v, #bowl2v, #bowl3v, #bowl4v, #bowl1h, #bowl2h, #bowl3h, #bowl4h', function(e) {
        console.log("Onchange PHP vis_options:"+JSON.stringify(vis_options)+"\r\n");
        console.log("Onchange PHP home_options:"+JSON.stringify(home_options)+"\r\n");


When changing one of the ids in the on change function, the ind_pts_game will display in the console. However, the vis_options & hope_options report as undefined.

Any insight on how to pass these correctly would be appreciated. They do display properly on page load, just now within the change function.

Related Questions

Updated May 08, 2019 13:10 PM

Updated May 30, 2019 19:10 PM

Updated March 26, 2015 07:25 AM

Updated April 08, 2015 18:04 PM

Updated July 02, 2015 13:04 PM