Hi...
Is it possible to copy a drop down list into another drop down list ?

<div id=firstdrop > 
<select >
<option value=1> one</option>
<option value=2> two</option>
<option value=3> three</option>
<option value=4> four</option>
 </select> 
</div>
<div id=seconddrop>

</div>
<script language=javascript>
document.getElementById("firstsecond").innerHTML=document.getElementById("firstdrop").innerHTML;
</script>

I want to copy the drop down list into a dynamic div.
I used the following code.
But it is not not working.

<form action="drop_copy.php">
<div id="firstdrop" > 
<select name="s[]">
<option value=1> one</option>
<option value=2> two</option>
<option value=3> three</option>
<option value=4> four</option>
 </select> 
</div>

<input name="" type="submit">
</form>
<script language="javascript">
var curr2=1;
var divTag = document.createElement("div");
       	divTag.id = "div"+curr2;
		
      
        divTag.setAttribute("align","left");
divTag.innerHTML=document.getElementById("firstdrop").innerHTML;
 document.getElementById("firstdrop").appendChild(divTag);
</script>

you can not append child to firstdrop its not container, you may append it to form element

This sort of thing is easily achieved with jQuery.

$("#firstdrop").find("select").clone().appendTo($("#seconddrop"));
//where id="seconddrop" is a block element (eg. div) or inline element (eg. span).

Any attached event handlers will be attached to the clone automatically.

I'm not sure about the current selectedIndex. It probably reverts to zero in the clone.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.