问题描述:

I need to populate a selection box based on the selection of a radio group and have managed to do so with this script:

function populate_slct_img_dimensions(){

var array1=["1","2","3"];

var array2=["4","5","6"];

var map = { radio_Img_1 : array1, radio_Img_2 : array2 }

$('#radio_Img_1, #radio_Img_2').click(function() {

$("#slct_img_dimensions option").remove();

$.each(map[this.id], function(i, val) {

var opt = $("<option />");

opt.appendTo($("#slct_img_dimensions")).text(val).val(val);

});

});

}

It works great but the issue is that I don't want the values to be the same as the labels.

opt.appendTo($("#slct_img_dimensions")).text(val).val(val);

The above line sets value and label to be the same. It appends the same array to both the label and the value of the selection box.

Could this script be modified to have different arrays for values so that they don't match the text labels?

网友答案:

Why are you concerned about if I have written it myself or not? It is a free non licensed script. Does it matter who have written it?

I'm developing a website and I'm not good at JavaScript. That's why I'm asking for help.

I have tried to duplicate the code so I have multiple sets of arrays and multiple sets of the second part of the code. I've also tried two separate functions.

Is it illegal to modify scripts you haven't written yourself?

相关阅读:
Top