tags:

views:

69

answers:

2

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());
+2  A: 

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

Russ Cam
Yes it is the id of the select
Roland
Your code works but it's adding the element, but I'm not able to selected that element
Roland
The value does not get an option tag eg value and not <option>value</option>
Roland
+1  A: 

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

peirix