4
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by Airshow
0
<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>
0

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>
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.