Forums

This topic is locked

Passing options between two selectboxes

Posted 23 Apr 2002 10:21:29
1
has voted
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>
&lt;script language="Javascript1.2"&gt;
&lt;!--
/**
* (2002) GoMotion Multimedia
* Hevel bepaalde opties uit Select1 over naar Select2
* Met dank aan Mathieu Kooiman &lt; &gt;
*
*
*/

selectedValues = new Array();

function isSelected(value)
{
for (i=0;i&lt;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;

}
//--&gt;
&lt;/script&gt;
&lt;body bgcolor="#FFCC99"&gt;
&lt;form method="post" action="bla.php"&gt;
&lt;table width="300" border="2" cellspacing="0" cellpadding="0" bordercolor="990000" align="center"&gt;
&lt;tr bgcolor="#E5B17F" bordercolor="#E5B17F"&gt;
&lt;td width="300"&gt;
&lt;select name="select1" size="6" multiple style="font-family: Verdana; font-size: 8 pt; border: 1 solid #808080"&gt;
&lt;?php while (($Repeat1__numRows-- != 0) && (!$Rs_get_trefwoord-&gt;EOF))
{
?&gt;
&lt;option value="&lt;?php echo $Rs_get_trefwoord-&gt;Fields("trefwoord"?&gt;" style="font-family: Verdana; font-size: 8 pt; border: 1 solid #808080"&gt;
&lt;?php echo $Rs_get_trefwoord-&gt;Fields("trefwoord"?&gt;
&lt;/option&gt;
&lt;?php
$Repeat1__index++;
$Rs_get_trefwoord-&gt;MoveNext();
}
?&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;select name="select2" size="6" multiple style="font-family: Verdana; font-size: 8 pt; border: 1 solid #808080"&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr bgcolor="990000"&gt;
&lt;td bordercolor="990000" height="30" bgcolor="990000"&gt;
&lt;div align="right"&gt;&lt;img src="../images/wiz_btns/ok.gif" width="44" height="28" onClick="hevelOverCurrSelected()"&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;td bordercolor="990000"&gt;
&lt;div align="right"&gt;&lt;img src="../images/wiz_btns/terug.gif" width="61" height="28" onClick="DeleteCurrSelected()"&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</font id=code></pre id=code>

You can find an example at:

www.klussenbank.nl/www/librabry/trefwoord_select.php

Thank you

Reply to this topic