• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Copy Element

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a combo box contains data loaded from server side. I want to duplicate this combo Element, which means I want the same content stored in the combo box and display it right next to the original one. Is there any fast way to copy an element in javascript ?


cheers

Transistor
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any reason why you can't just do it on the server side?

--Nimchi
 
YuenLian Wu
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my form contains a lot of elements, and I wish I can do it at once, just like java, write once, run anywhere
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
might be able to try to clone the node of the select element, not sure if it will copy all of the options. Probbaly the easiest thing is to use createElement with the select and than use new Option() with a for loop.

Eric
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just do like this,use the method cloneNode() to clone a node and add it to anywhere you want by appendChild()...

<select id="ddddd"><option value="dddd">fasdfd</option></select>
<SCRIPT LANGUAGE="JavaScript">
<!--
var obj = document.getElementById("ddddd").cloneNode(true);
document.body.appendChild(obj);
//-->
</SCRIPT>

[Edit: non-English content removed]
[ December 05, 2006: Message edited by: Bear Bibeault ]
 
matrixy herry
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Edit: non-English content removed]
[ December 05, 2006: Message edited by: Bear Bibeault ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic