can't post form with listbox with javascript
And yes, the code is meshed up but that's for later..
Hope someone can help me!
Code (php)
<SCRIPT LANGUAGE="JavaScript">
<!--
function moveOver() {
var boxLength = document.usergroup.members.length;
var selectedItem = document.usergroup.users.selectedIndex;
var selectedText = document.usergroup.users.options[selectedItem].text;
var selectedValue = document.usergroup.users.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.usergroup.members.options.text;
if (thisitem == selectedText) {
isNew = false;
break;
}
}
}
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.usergroup.members.options[boxLength] = newoption;
}
document.usergroup.users.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.usergroup.members.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.usergroup.members.options.selected) {
arrSelected[count] = document.usergroup.members.options.value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.usergroup.members.options.value == arrSelected[x]) {
document.usergroup.members.options = null;
}
}
boxLength = document.usergroup.members.length;
}
}
// -->
</script>
Code (php)
1
2
3
4
2
3
4
<?php
//$result1 = querydb("SELECT userID, firstName FROM user");
//$result2 = querydb('SELECT user.userID, firstName FROM user, user_group WHERE user.userID = user_group.userID and user_group.groupID = "1"');
?>
//$result1 = querydb("SELECT userID, firstName FROM user");
//$result2 = querydb('SELECT user.userID, firstName FROM user, user_group WHERE user.userID = user_group.userID and user_group.groupID = "1"');
?>
<form name="usergroup" method="post" action="test3.php">
<table>
<tr>
<td>Users:</td>
<td>Groupmembers:</td>
</tr>
<tr>
<td>
<select name="users" size=10 onchange="moveOver();">
Code (php)
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
<?php
//for($i=0; $i<count($result1); $i++){
//echo('<option value='.$result1[$i]->userID.'>'.$result1[$i]->firstName.'</option>');
//}
echo ('<option value="piet">Piet</option>');
echo ('<option value="jan">Jan</option>');
echo ('<option value="klaas">Klaas</option>');
echo ('<option value="rene">Rene</option>');
echo ('<option value="gerrit">Gerrit</option>');
echo ('<option value="dirk">Dirk</option>');
?>
//for($i=0; $i<count($result1); $i++){
//echo('<option value='.$result1[$i]->userID.'>'.$result1[$i]->firstName.'</option>');
//}
echo ('<option value="piet">Piet</option>');
echo ('<option value="jan">Jan</option>');
echo ('<option value="klaas">Klaas</option>');
echo ('<option value="rene">Rene</option>');
echo ('<option value="gerrit">Gerrit</option>');
echo ('<option value="dirk">Dirk</option>');
?>
</select>
</td>
<td>
<select multiple name="members" style="width:150;" size="10" onchange="removeMe();">
Code (php)
</select>
</td>
</tr>
<tr>
<td><input type="submit" name="submit" value=" OK "></td>
</tr>
</form>
en dan?? Het probleem is juist dat die waardes niet in $_POST zitten...... :S
Isn't tis a Duts forum :)
Het lukt me niet het form/de listbox te posten zodat ik het op de volgende pagina kan gebruiken. Dit is de eerste keer dat ik iets op dit forum post dus ik hoop dat m'n script leesbaar is. En ja, de code is een zooitje maar dat komt later wel.
Hoop dat iemand me kan helpen!
----
Nu graag je oplossing Mitch!
if($_POST[submit])
{
// actie
}
else
{
// formuliertje met listboxes :)
}
If you want the values of the multiple select boxes you need to have them highlighted (selected)...
It kind off comes with the name ;)
this you have to fix in javascript.. here's how (first let me do the dutch aswell)
Het probleem ligt in het gebruik van Multiple select boxen .. alleen die waarden die geselecteerd zijn worden doorgegeven ... met javascript moet je dus eerst alle waardes selecteren...
het javascriptje
function selectall()
{
var o = document.combo_box['FIELDNAME[]'].options
for (var i = 0; i < o.length; i++)
{
var optie = o;
optie.selected = true;
}
}
greets en mvg
Peanuts