Adding values to a dropdown <select> box using JQuery

jquery

Solution

I think you want

$('#pages').append($('#t1').val());

assuming pages is the id of your `<select>`. Also, `$('#t1').val()` should be an `<option>` element, not a value. Something like this

 var newOption = $('<option value="'+val+'">'+val+'</option>');
 $('#pages').append(newOption);

or

var newOption = $('<option>');
newOption.attr('value',val).text(val);
 $('#pages').append(newOption);

whichever is easier for you to read.

Here's a Working Demo

Problem

I have a issue with populating values in a box using JQuery. Instead of adding it underneath each other it adds it next to all other elements my code ``` $('#pages option').append($('#t1').val()); ```

Original source