[Answer]-Accessing global variables after setting them javascript

1👍

You can use Object as associative array.

var changed_select_box_array = {};

function handleChanges() {
    var x = this.selectedIndex;
    var id = this.id;
    var time = this.getElementsByTagName("option")[x].value;
    var change = { id: id, new_time: time };
    changed_select_box_array[id] = change;
    console.log(changed_select_box_array);
}
<!--Emitation of some select inputs with change events-->
<select id="s1" onchange="handleChanges.call(this)">
    <option value="val1">Value 1</option>
    <option value="val2">Value 2</option>
    <option value="val3">Value 3</option>
</select>

<select id="s2" onchange="handleChanges.call(this)">
    <option value="val4">Value 1</option>
    <option value="val5">Value 2</option>
    <option value="val6">Value 3</option>
</select>

Leave a comment