0

I have 2 dropdownboxes.

<select id='SerK1'><option values="123">123</option></select>
<select id='SerK2'></select>

Then I wanna copy contents from SerK1 to SerK2

document.getElementById('SerK2').innerHTML+=document.getElementById('SerK1').innerHTML;
alert(document.getElementById('SerK1').innerHTML);

This prints out the expected result : 123

alert(document.getElementById('SerK2').innerHTML);

However, for this one, it somehow removes the and came up with only 123 in the pop up alert screen.

Any ideas how to fix this?

Cheers

Charlie
  • 11,380
  • 19
  • 83
  • 138
  • 1
    Possible duplicate of: http://stackoverflow.com/questions/595808/is-it-possible-to-append-to-innerhtml-without-destroying-descendants-onclick-fu – vee Jul 20 '13 at 05:48

3 Answers3

0

You can easily do this with jquery Try this

$('#SerK2').html($('#SerK1').html());

Try This Fiddle

Ishan Jain
  • 8,063
  • 9
  • 48
  • 75
nrsharma
  • 2,532
  • 3
  • 20
  • 36
0

Try this

document.getElementById('SerK2').innerHTML = document.getElementById('SerK1').innerHTML;

JSFiddle

Nithesh Narayanan
  • 11,481
  • 34
  • 98
  • 138
0

Please try this --

   $(document).ready(function(){
     document.getElementById('SerK2').innerHTML = document.getElementById('SerK1').innerHTML
   });

Try

Ishan Jain
  • 8,063
  • 9
  • 48
  • 75