1

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]) );
    };
ssatish4u
  • 131
  • 2
  • 9
  • Possible duplicate of [How to dynamically add elements via jQuery](https://stackoverflow.com/questions/8935533/how-to-dynamically-add-elements-via-jquery) – JanWillem Huising Aug 31 '18 at 09:07
  • Possible duplicate of [How to add Drop-Down list ( – ggorlen Sep 26 '19 at 04:12

1 Answers1

1

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>
Dhaval Pankhaniya
  • 1,996
  • 1
  • 15
  • 26