Forums
This topic is locked
Passing options between two selectboxes
23 Apr 2002 10:21:29 D Adema posted:
<font face='Tahoma'>Hello everyone,
The following script enables users to add selected options from a selectbox to another.
Also, it should be possible to delete options from the second selectbox.
But or some reason it won't. I can't figure out why.
Can someone help me?
</font id='Tahoma'>
<pre id=code><font face=courier size=2 id=code>
<script language="Javascript1.2">
<!--
/**
* (2002) GoMotion Multimedia
* Hevel bepaalde opties uit Select1 over naar Select2
* Met dank aan Mathieu Kooiman < >
*
*
*/
selectedValues = new Array();
function isSelected(value)
{
for (i=0;i<selectedValues.length;i++) {
if (selectedValues[i] == value) {
return true;
}
}
return false;
}
function hevelOverCurrSelected()
{
select1 = document.forms[0].select1;
s1SelOpt = select1.options[select1.selectedIndex];
select2 = document.forms[0].select2;
if (!isSelected(s1SelOpt.value)) {
select2.options[select2.options.length] = new Option(s1SelOpt.text, s1SelOpt.value,0,0);
selectedValues[selectedValues.length] = s1SelOpt.value;
} else {
alert("Trefwoord is al geselecteerd: " + s1SelOpt.value);
}
}
function DeleteCurrSelected()
{
select2.options[select2.selectedIndex] = null;
}
//-->
</script>
<body bgcolor="#FFCC99">
<form method="post" action="bla.php">
<table width="300" border="2" cellspacing="0" cellpadding="0" bordercolor="990000" align="center">
<tr bgcolor="#E5B17F" bordercolor="#E5B17F">
<td width="300">
<select name="select1" size="6" multiple style="font-family: Verdana; font-size: 8 pt; border: 1 solid #808080">
<?php while (($Repeat1__numRows-- != 0) && (!$Rs_get_trefwoord->EOF))
{
?>
<option value="<?php echo $Rs_get_trefwoord->Fields("trefwoord"?>" style="font-family: Verdana; font-size: 8 pt; border: 1 solid #808080">
<?php echo $Rs_get_trefwoord->Fields("trefwoord"?>
</option>
<?php
$Repeat1__index++;
$Rs_get_trefwoord->MoveNext();
}
?>
</select>
</td>
<td>
<select name="select2" size="6" multiple style="font-family: Verdana; font-size: 8 pt; border: 1 solid #808080">
</select>
</td>
</tr>
<tr bgcolor="990000">
<td bordercolor="990000" height="30" bgcolor="990000">
<div align="right"><img src="../images/wiz_btns/ok.gif" width="44" height="28" onClick="hevelOverCurrSelected()"></div>
</td>
<td bordercolor="990000">
<div align="right"><img src="../images/wiz_btns/terug.gif" width="61" height="28" onClick="DeleteCurrSelected()"></div>
</td>
</tr>
</table>
</form>
</body>
</html>
</font id=code></pre id=code>
You can find an example at:
www.klussenbank.nl/www/librabry/trefwoord_select.php
Thank you