While attempting to update a global array using JavaScript, I encountered an issue where I couldn't access anything about it within a function. Removing the if/else statement allowed the alert for new_time to work, but the final alert did not display. Unfortunately, including the if/else statement caused my code to malfunction, halting its execution altogether. Despite knowing that global variables can be accessed simply by their name, why does changed_select_box_array
present challenges in this context? (I also attempted to reference it as global., window., and this.)
var one = document.optionObject("id_open_time_1");
var changed_select_box_array = [];
function showID(id){
if (changed_select_box_array.length > 0){
alert('somethin');
}
else{
alert('nuttin');
}
var x = document.getElementById(id).selectedIndex;
var time = document.getElementsByTagName("option")[x].value;
var change = {id:id, new_time:time};
alert(change.new_time);
changed_select_box_array.push(change);
alert(changed_select_box_array[0].id);
}
Interestingly, the snippet below (which had been innocuous for several days) seemed to be the cause of the problem:
var one = document.optionObject("id_open_time_1");
I'm curious to understand why that particular line is causing issues.