How can I add element to an array calling a function with the onchange event?
I have a drop down list box and onchange I'm calling a function which should push this value to an array. The array keeps returning only one value.
Here is the js function:
function multSubType(sel){
var objSel = document.getElementById('subType'+sel);
var valSel = new Arra开发者_如何学Goy();
valSel.push(objSel.value);
}
Everytime the function executes, you're creating the array all over again. Move the variable declaration and array assignment outside the scope of the function:
var valSel = new Array();
function multSubType(sel) {
var objSel = document.getElementById('subType' + sel);
valSel.push(objSel.value);
}
精彩评论