Jquery function passing around select options -


$('#addallbutton').click(function () {             var options = '';             $('#fromlist').find('option').each(function () {                 alert($(this).val());                 //options += '<option value="' + $(this).val() + '">' + $(this).text() + '</option>';             });             $('#tolist').append(options);         });  <select id="fromlist" name="drop1" class="listbox" multiple="multiple">                     <option value="1">item 1</option>                     <option value="2">item 2</option>                     <option value="3">item 3</option>                     <option value="4">item 4</option>                     <option value="0">all</option> </select>  <select id="tolist" name="drop1" class="listbox" multiple="multiple">                         <option value="1">item 1</option>                         <option value="2">item 2</option>                         <option value="3">item 3</option>                         <option value="4">item 4</option>                         <option value="0">all</option>     </select> 

i have button add all. want button add every option fromlist select list tolist. function doesn't seem working, can point me in right direction?

i tried use part of code spyk3hh:

$('#addallbutton').click(function () {                 //options += '<option value="' + $(this).val() + '">' + $(this).text() + '</option>';                 $('#fromlist').children().appendto($("#tolist"));             }); 

i couldn't work. have button called add all, when click it move #fromlist #tolist. above doesn't seem working either.

to move all options first list second:

$('#addallbutton').click(function() {     var options = $('#fromlist').find('option');     $('#tolist').append(options); });​ 

js fiddle demo.

if, seems comments/answers elsewhere, want move except last of option elements, then:

$('#addallbutton').click(function() {     var options = $('#fromlist').find('option').slice(0,$('#fromlist').find('option').length -1);     $('#tolist').append(options); });​ 

js fiddle demo.

references:


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -