Selecteren en schuiven
Heb 2 vakken. Links aan aantal namen. Rechts is leeg. 3 knoppen met linker en rechter pijl en verzenden. Nu kan de gebruiker een naam selecteren en op pijl klikken en dan zou de naam naar rechts moeten in een nieuwe lijst. Ook kan hij de naam weer naar links verplaatsen. Na knop verzenden komt een controle.
Wie heeft een voorzet hoe dit te doen in PHP?
In eerste instantie heb je iets javascript achtigs nodig dat het netjes van het ene naar het andere vak veranderd. Het php controle verhaal komt daarna pas. :)
Ergens een klein voorbeeld te vinden. Ben niet echt bekend met Java
http://blog.jeremymartin.name/2008/02/easy-multi-select-transfer-with-jquery.html
Zoiets bedoel je denk ik.. :)
Zoiets bedoel je denk ik.. :)
Het is javascript he, dat is weer totaal anders dan java :)
Ja dat bedoel ik. Merci voor de reacties
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options.text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options.selected) {
arrSelected[count] = document.choiceForm.choiceBox.options.value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options.value == arrSelected[x]) {
document.choiceForm.choiceBox.options = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options.value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options.value;
}
count++;
}
}
}
// End -->
</script>
</head>
<body>
<center>
<form name="choiceForm">
<select name="available" size=10 onchange="moveOver();">
<option value=1>Keuze 1
<option value=2>Keuze 2
<option value=3>Keuze 3
<option value=4>Keuze 4
<option value=5>Keuze 5
<option value=6>Keuze 6
<option value=7>Keuze 7
<option value=8>Keuze 8
<option value=9>Keuze 9
<option value=10>Keuze 10
</select>
<select multiple name="choiceBox" style="width:150;" size="10">
</select>
</center>
<br />
</form><br />
<center><input type="button" value="Verwijder" onclick="removeMe();"></center>
</body>
</html>
Code (php)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options.text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++;
}
}
}
// End -->
</script>
</head>
<body>
<center>
<form name="choiceForm" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p>
<input type="submit" value="verzenden" />
</p>
<select name="available" size=10 onchange="moveOver();">
<option value=1>Keuze 1
<option value=2>Keuze 2
<option value=3>Keuze 3
<option value=4>Keuze 4
<option value=5>Keuze 5
<option value=6>Keuze 6
<option value=7>Keuze 7
<option value=8>Keuze 8
<option value=9>Keuze 9
<option value=10>Keuze 10
</select>
<select multiple id="choiceBox" name="choiceBox[]" style="width:150;" size="10">
</select>
</center>
<br />
</form><br />
<center><input type="button" value="Verwijder" onclick="removeMe();"></center>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<pre>' . print_r ($_POST, true) . '</pre>';
}
?>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function moveOver()
{
var boxLength = document.choiceForm.choiceBox.length;
var selectedItem = document.choiceForm.available.selectedIndex;
var selectedText = document.choiceForm.available.options[selectedItem].text;
var selectedValue = document.choiceForm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.choiceForm.choiceBox.options.text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.choiceForm.choiceBox.options[boxLength] = newoption;
}
document.choiceForm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.choiceForm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.choiceForm.choiceBox.options[i].selected) {
arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
document.choiceForm.choiceBox.options[i] = null;
}
}
boxLength = document.choiceForm.choiceBox.length;
}
}
function saveMe() {
var strValues = "";
var boxLength = document.choiceForm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.choiceForm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
}
count++;
}
}
}
// End -->
</script>
</head>
<body>
<center>
<form name="choiceForm" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
<p>
<input type="submit" value="verzenden" />
</p>
<select name="available" size=10 onchange="moveOver();">
<option value=1>Keuze 1
<option value=2>Keuze 2
<option value=3>Keuze 3
<option value=4>Keuze 4
<option value=5>Keuze 5
<option value=6>Keuze 6
<option value=7>Keuze 7
<option value=8>Keuze 8
<option value=9>Keuze 9
<option value=10>Keuze 10
</select>
<select multiple id="choiceBox" name="choiceBox[]" style="width:150;" size="10">
</select>
</center>
<br />
</form><br />
<center><input type="button" value="Verwijder" onclick="removeMe();"></center>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo '<pre>' . print_r ($_POST, true) . '</pre>';
}
?>
</body>
</html>
Gewijzigd op 01/01/1970 01:00:00 door Ed Wisseborn
Bumpen::
Gewijzigd op 01/01/1970 01:00:00 door Ed Wisseborn
http://be.php.net/manual/en/reserved.variables.server.php
(voor die $_SERVER['REQUEST_URI'])
Gewijzigd op 01/01/1970 01:00:00 door Emmanuel Delay
Merci emmanuel maar was er al mee bezig. W.b.t dat bumpen, beetje kinderachtig om op een uur te kijken.
Ed Wisseborn schreef op 10.07.2008 17:25:
Merci emmanuel maar was er al mee bezig. W.b.t dat bumpen, beetje kinderachtig om op een uur te kijken.
Ook 1 uur te vroeg, is te vroeg. Als we gaan beginnen de regels "met een korreltje zout" te nemen, dan is het einde snel zoek..
Groetjes, Edje