1

I have 3 array one for value and 2nd one for option name and third one for price.

I want to create dynamic option list using value and option name (value is channel id and channel name)

on selection of channel name display sum of price of channel in other textbox

i am using below query to display 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
  • 121
  • 2
  • 8
  • 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,998
  • 1
  • 13
  • 26