开发者

How can I add element to an array calling a function with the onchange event?

开发者 https://www.devze.com 2023-02-05 12:25 出处:网络
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.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号