Reputation: 131
I have 3 arrays: one for the value, and 2nd one for the option name, and the third one for the price.
I want to create a dynamic option list using value and option name (value is channel id and channel name) and, on selection of the channel name, display the sum of the price of the channel in the other textbox.
I am using the below to display the dynamic option name:
var select = document.getElementById("selectNumber4");
var options = channel;
console.log(options);
$('#selectNumber4').html('');
for( option in options ) {
select.add( new Option( options[option]) );
};
Upvotes: 1
Views: 5657
Reputation: 1996
simply try following
var select = $("<select></select>");
var chanels = ["chanel1", "chanel2", "chanel3"]
var chanelValue = ["1", "2", "3"]
for(var i=0;i<chanels.length;i++){
var option = $("<option></option>");
$(option).val(chanelValue[i]);
$(option).html(chanels[i]);
$(select).append(option);
}
$(".default").append(select);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="default">
<div>
Upvotes: 1