Copy Option List From Dropdownlist. Jquery
Html code
Solution 1:
$('#dropdwon1 option').clone().appendTo('#dropdwon2');
Solution 2:
Can you make it "clone" currently (not initial) selected item too?
$('#dropdwon1 option').eq(1).attr('selected', 'selected');
$('#dropdwon1 option').clone().appendTo('#dropdwon2');
Solution 3:
Jquery clone is normaly the way to go but it doesn't work well with items such as select check and radio
The work around is to set the html dom attributes before cloning here is how i do it
var selects = $('form').find('select') ;
selects.each ( function () {
var selvalue = $( this ).val() ;
var options = $( this ).find('option') ;
options.each ( function () {
if ( $( this ).attr( 'value' ) == selvalue )
$( this ).attr( 'selected' , true ) ;
});
}) ;
$('form').clone.appendTo( '#target' )
Setting the selected dom attribute to true allow clone to copy the value effectively
Solution 4:
Try this:
$('#dropdwon2')[0].options = $('#dropdwon1')[0].options;
Post a Comment for "Copy Option List From Dropdownlist. Jquery"