Toon posts:

[php] multiple selection form

Pagina: 1
Acties:
  • 34 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik heb een form met een multiple selection form. De multiple selection is als volgt gedefinieert:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<input type="hidden" id="func_status" onClick="javascript:if(document.frm_criteria.functies.options.length == 0) this.checked = false; else {this.checked = true;}"> 
</td>
<td > <select name="functie_besch" size="4" style="width:200" multiple >
<?
$sql="SELECT functienr, functienaam FROM functie order by functienaam";
$resultaat = mysql_query($sql) or die (mysql_error());
While ($row = mysql_fetch_array($resultaat, MYSQL_NUM)) { ?>
<option value="<? echo $row[0]; ?>"><? echo $row[1]; ?> 
<? } ?>
</select></td>
<td> <input name="button" type="button" style="width=30" onClick="f_setlist('functie_besch','functies','func_status')" value="-->">
<br> <input name="button" type="button" style="width=30" onClick="del_list('functies','func_status')" value="<--"> 
</td>
<td> <select name="functies[]" size="4" style="width:200" multiple>
</select>


Hierbij wordt zoals je ziet gebruik gemaakt van een javascript, als volgt gedefinieert:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<script language="JavaScript">

function f_setlist(firstlist,secondlist,combo)
{
first = eval("document.frm_criteria." + firstlist);
second = eval("document.frm_criteria." + secondlist);
com = eval("document.frm_criteria." + combo);
 for (i=0;i < first.options.length;i++)
 {
  if (first.options[i].selected == true)
   {
     exit = false;
     for (j=0; j< second.options.length;j++)
     {
       if (first.options[i].text == second.options[j].text)
       {
         exit = true;
         j = second.options.length;
       }
     }
     if (exit == false)
     {
     ins = first.options[i].text;
     val = first.options[i].value;
     pos = second.options.length;
     second.options[pos]= new Option(ins,val);
     com.checked = true;
     }
   }
 }
}

function del_list(secondlist,combo)
{
second = eval("document.frm_criteria." + secondlist);
com = eval("document.frm_criteria." + combo);
 for (i=0;i < second.options.length;i++)
 {
  if (second.options[i].selected == true)
   {
      second.options[i] = null;
      i--;
   }
 }
if (second.options.length == 0)
{com.checked = false;}
}
</script>


Als ik nu test, blijkt dat er een fout in het javascript zit en dat ik niet meer de waardes uit de linker list naar de rechter list kan verplaatsen. Ik heb ook al geprobeerd om 'functies' in het javascript te vervangen door 'functies[]', maar dan krijg ik een syntaxfout. Voor de verdere verwerking van het form, is het nodig dat de waardes uit 'functies' doorgegeven worden als array.

Mvg, Mark.

  • whoami
  • Registratie: December 2000
  • Laatst online: 10:21
Blijkbaar wil jij echt de FAQ niet lezen, terwijl dit al meerdere malen vermeld geweest is.
Javascript hoort thuis in W&G , en niet in P&W.

Welkom in P&W (FAQ-15/10/2002)

https://fgheysels.github.io/


Dit topic is gesloten.