Volitics
03-15-2005, 09:45 PM
Hello;
Can anybody tell me how to get the chosen items below (on Picklist.php page) to output on PickListDisplay.php page in an array that I can insert into a MySQL database?
Unlike the PHP manual and the MySQL manual there does not appear to be a manual for JavaScript.
(Here is where I got the JavaScript code: http://www.quirksmode.org/js/transfer.html)
Does anybody know where there is a good tutorial that might help me to learn JavaScript?
// PickList.php
// header of the page.
function copyToList(from,to)
{
fromList = eval('document.forms[0].' + from);
toList = eval('document.forms[0].' + to);
if (toList.options.length > 0 && toList.options[0].value == 'temp')
{
toList.options.length = 0;
}
var sel = false;
for (i=0;i<fromList.options.length;i++)
{
var current = fromList.options[i];
if (current.selected)
{
sel = true;
if (current.value == 'temp')
{
alert ('You cannot move this text!');
return;
}
txt = current.text;
val = current.value;
toList.options[toList.length] = new Option(txt,val);
fromList.options[i] = null;
i--;
}
}
if (!sel) alert ('You havent selected any options!');
}
function allSelect()
{
List = document.forms[0].chosen;
if (List.length && List.options[0].value == 'temp') return;
for (i=0;i<List.length;i++)
{
List.options[i].selected = true;
}
}
// html starts here.
<FORM action="PickListDisplay.php" onSubmit="allSelect(); return true">
<TABLE CELLPADDING=10 CELLSPACING=0 BORDER=1>
<TR><TD><P>Possible options:<BR>
<SELECT NAME="possible" SIZE="4" MULTIPLE WIDTH=200 STYLE="width: 200px">
<OPTION VALUE="House">Option 1: House</OPTION>
<OPTION VALUE="Chamber">Option 2: Chamber</OPTION>
<OPTION VALUE="Kitchen">Option 3: Kitchen</OPTION>
<OPTION VALUE="Garden">Option 4: Garden</OPTION>
</SELECT></TD>
<TD><A HREF="javascript:copyToList('possible','chosen')">--></A><BR>
<A HREF="javascript:copyToList('chosen','possible')"><--</A></TD>
<TD><P>Chosen options:<BR>
<SELECT NAME="chosen" SIZE="4" MULTIPLE WIDTH=200 STYLE="width: 200px">
<OPTION VALUE="temp">Make your choice on the left
</SELECT></TD></TR>
<TR><TD COLSPAN=3 ALIGn=center><INPUT TYPE=submit VALUE="submit"></TD></TR>
</TABLE>
</FORM>
// PickListDisplay.php (outputs "Gard" - first four letters in Option 4)
// If the user picks all four options on PickList.php how do I get them to output?
$Output = "$chosen[0] $chosen[1] $chosen[2] $chosen[3]";
$Output = explode(" ", $Output);
echo $Output[0];
echo $Output[1];
echo $Output[2];
echo $Output[3];
// I want this to output "House," "Garden," "Kitchen," and "Garden" if all four items are chosen on PickList.php (I want to insert them into the MySQL database).
Thanks.
Can anybody tell me how to get the chosen items below (on Picklist.php page) to output on PickListDisplay.php page in an array that I can insert into a MySQL database?
Unlike the PHP manual and the MySQL manual there does not appear to be a manual for JavaScript.
(Here is where I got the JavaScript code: http://www.quirksmode.org/js/transfer.html)
Does anybody know where there is a good tutorial that might help me to learn JavaScript?
// PickList.php
// header of the page.
function copyToList(from,to)
{
fromList = eval('document.forms[0].' + from);
toList = eval('document.forms[0].' + to);
if (toList.options.length > 0 && toList.options[0].value == 'temp')
{
toList.options.length = 0;
}
var sel = false;
for (i=0;i<fromList.options.length;i++)
{
var current = fromList.options[i];
if (current.selected)
{
sel = true;
if (current.value == 'temp')
{
alert ('You cannot move this text!');
return;
}
txt = current.text;
val = current.value;
toList.options[toList.length] = new Option(txt,val);
fromList.options[i] = null;
i--;
}
}
if (!sel) alert ('You havent selected any options!');
}
function allSelect()
{
List = document.forms[0].chosen;
if (List.length && List.options[0].value == 'temp') return;
for (i=0;i<List.length;i++)
{
List.options[i].selected = true;
}
}
// html starts here.
<FORM action="PickListDisplay.php" onSubmit="allSelect(); return true">
<TABLE CELLPADDING=10 CELLSPACING=0 BORDER=1>
<TR><TD><P>Possible options:<BR>
<SELECT NAME="possible" SIZE="4" MULTIPLE WIDTH=200 STYLE="width: 200px">
<OPTION VALUE="House">Option 1: House</OPTION>
<OPTION VALUE="Chamber">Option 2: Chamber</OPTION>
<OPTION VALUE="Kitchen">Option 3: Kitchen</OPTION>
<OPTION VALUE="Garden">Option 4: Garden</OPTION>
</SELECT></TD>
<TD><A HREF="javascript:copyToList('possible','chosen')">--></A><BR>
<A HREF="javascript:copyToList('chosen','possible')"><--</A></TD>
<TD><P>Chosen options:<BR>
<SELECT NAME="chosen" SIZE="4" MULTIPLE WIDTH=200 STYLE="width: 200px">
<OPTION VALUE="temp">Make your choice on the left
</SELECT></TD></TR>
<TR><TD COLSPAN=3 ALIGn=center><INPUT TYPE=submit VALUE="submit"></TD></TR>
</TABLE>
</FORM>
// PickListDisplay.php (outputs "Gard" - first four letters in Option 4)
// If the user picks all four options on PickList.php how do I get them to output?
$Output = "$chosen[0] $chosen[1] $chosen[2] $chosen[3]";
$Output = explode(" ", $Output);
echo $Output[0];
echo $Output[1];
echo $Output[2];
echo $Output[3];
// I want this to output "House," "Garden," "Kitchen," and "Garden" if all four items are chosen on PickList.php (I want to insert them into the MySQL database).
Thanks.