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
  • 10,718
  • 17
  • 78
  • 137
  • 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
  • 7,819
  • 9
  • 46
  • 75
nrsharma
  • 2,477
  • 1
  • 17
  • 36
0

Try this

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

JSFiddle

Nithesh Narayanan
  • 10,803
  • 33
  • 93
  • 136
0

Please try this --

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

Try

Ishan Jain
  • 7,819
  • 9
  • 46
  • 75