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());
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());
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
You probably want something along the lines of
$("#pages").append("<option>"+$("#t1").val()+"</option>");
That will make and append an option to your select box