Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Copy Element

 
YuenLian Wu
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • 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
 
Nimchi Yung
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
 
matrixy herry
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
[Edit: non-English content removed]
[ December 05, 2006: Message edited by: Bear Bibeault ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic