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]) );
    };
2

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

2 Comments

nos of array is dynamic for key/value (channel_id,channel_name)
And also i want to show price on select of channel in text box

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.