开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜