jmol
01-19-2006, 10:47 AM
I have two selectboxes containing several option.
I am able to move options from one selectbox to the other selectbox (by .insertBefore for example).
However, when I clone those selectboxes, the cloned selectboxes behave incorrect. I am able to move options from one to the other, but they won't show correctly. Only after a browser resize or minimize/maximize window will the selectboxes be 'refreshed' to reflect their real content.
See the following code example. Bottom selectboxes are clones of the top ones.
<HTML>
<HEAD>
<style>
select
{
width: expression(document.body.clientWidth / 3);
height: expression(document.body.clientHeight / 3);
}
</style>
<SCRIPT>
// move selected options from source to destination selectbox
function SwapSelected(oSrc, oDest)
{
var oDestOption = null;
if(oSrc.length > 0)
for(var i=oSrc.length-1; i>=0; i--)
if(oSrc.options[i].selected)
{
oDest.insertBefore(oSrc.options[i]); // object will be moved
}
}
// clone selectboxes to bottom table
function cloneTopSelectboxesToBottom()
{
var oCloneL = oSelBxLeftOne.cloneNode(true); // clone
var oCloneR = oSelBxRightOne.cloneNode(true);
oCloneL.id = "oSelBxLeftTwo"; // mage unique
oCloneR.id = "oSelBxRightTwo";
leftTd.insertBefore(oCloneL); // insert
rightTd.insertBefore(oCloneR);
}
</SCRIPT>
</HEAD>
<BODY onload="cloneTopSelectboxesToBottom();">
Hard coded select/options:
<TABLE>
<TR>
<TD>
<select id="oSelBxLeftOne" multiple="multiple">
<option value='1'>one
<option value="2">two
<option value="3">three
<option value="4">four
</select>
</TD>
<TD>
<INPUT TYPE="button" onclick="SwapSelected(oSelBxLeftOne,oSelBxRightOne);" value="move right"><br>
<INPUT TYPE="button" onclick="SwapSelected(oSelBxRightOne,oSelBxLeftOne);" value="move left">
</TD>
<TD>
<select id="oSelBxRightOne" multiple="multiple">
<option value='5'>five
<option value="6">six
<option value="7">seven
<option value="8">eight
</select>
</TD>
</TR>
</TABLE>
<hr>
Cloned select/options (clones of the top hard coded ones):
<TABLE>
<TR>
<TD id="leftTd" />
<TD>
<INPUT TYPE="button" onclick="SwapSelected(oSelBxLeftTwo,oSelBxRightTwo);" value="move right"><br>
<INPUT TYPE="button" onclick="SwapSelected(oSelBxRightTwo,oSelBxLeftTwo);" value="move left">
</TD>
<TD id="rightTd" />
</TR>
</TABLE>
</BODY>
</HTML>
Only work-around I can think of getting them 'refreshed' by code, is by doing a clone-delete-insert after every move action, like calling the following function at the end of function SwapSelected().
function reFreshClones()
{
var oTmpL = oSelBxLeftTwo.cloneNode(true);
var oTmpR = oSelBxRightTwo.cloneNode(true);
oSelBxLeftTwo.removeNode(true);
oSelBxRightTwo.removeNode(true);
leftTd.insertBefore(oTmpL);
rightTd.insertBefore(oTmpR);
}
As you'll understand, this work-around does not really please me...
Anybody knows how to fix (work-around) this weird behaviour?
I am able to move options from one selectbox to the other selectbox (by .insertBefore for example).
However, when I clone those selectboxes, the cloned selectboxes behave incorrect. I am able to move options from one to the other, but they won't show correctly. Only after a browser resize or minimize/maximize window will the selectboxes be 'refreshed' to reflect their real content.
See the following code example. Bottom selectboxes are clones of the top ones.
<HTML>
<HEAD>
<style>
select
{
width: expression(document.body.clientWidth / 3);
height: expression(document.body.clientHeight / 3);
}
</style>
<SCRIPT>
// move selected options from source to destination selectbox
function SwapSelected(oSrc, oDest)
{
var oDestOption = null;
if(oSrc.length > 0)
for(var i=oSrc.length-1; i>=0; i--)
if(oSrc.options[i].selected)
{
oDest.insertBefore(oSrc.options[i]); // object will be moved
}
}
// clone selectboxes to bottom table
function cloneTopSelectboxesToBottom()
{
var oCloneL = oSelBxLeftOne.cloneNode(true); // clone
var oCloneR = oSelBxRightOne.cloneNode(true);
oCloneL.id = "oSelBxLeftTwo"; // mage unique
oCloneR.id = "oSelBxRightTwo";
leftTd.insertBefore(oCloneL); // insert
rightTd.insertBefore(oCloneR);
}
</SCRIPT>
</HEAD>
<BODY onload="cloneTopSelectboxesToBottom();">
Hard coded select/options:
<TABLE>
<TR>
<TD>
<select id="oSelBxLeftOne" multiple="multiple">
<option value='1'>one
<option value="2">two
<option value="3">three
<option value="4">four
</select>
</TD>
<TD>
<INPUT TYPE="button" onclick="SwapSelected(oSelBxLeftOne,oSelBxRightOne);" value="move right"><br>
<INPUT TYPE="button" onclick="SwapSelected(oSelBxRightOne,oSelBxLeftOne);" value="move left">
</TD>
<TD>
<select id="oSelBxRightOne" multiple="multiple">
<option value='5'>five
<option value="6">six
<option value="7">seven
<option value="8">eight
</select>
</TD>
</TR>
</TABLE>
<hr>
Cloned select/options (clones of the top hard coded ones):
<TABLE>
<TR>
<TD id="leftTd" />
<TD>
<INPUT TYPE="button" onclick="SwapSelected(oSelBxLeftTwo,oSelBxRightTwo);" value="move right"><br>
<INPUT TYPE="button" onclick="SwapSelected(oSelBxRightTwo,oSelBxLeftTwo);" value="move left">
</TD>
<TD id="rightTd" />
</TR>
</TABLE>
</BODY>
</HTML>
Only work-around I can think of getting them 'refreshed' by code, is by doing a clone-delete-insert after every move action, like calling the following function at the end of function SwapSelected().
function reFreshClones()
{
var oTmpL = oSelBxLeftTwo.cloneNode(true);
var oTmpR = oSelBxRightTwo.cloneNode(true);
oSelBxLeftTwo.removeNode(true);
oSelBxRightTwo.removeNode(true);
leftTd.insertBefore(oTmpL);
rightTd.insertBefore(oTmpR);
}
As you'll understand, this work-around does not really please me...
Anybody knows how to fix (work-around) this weird behaviour?