Request List Box Values as an array
Posted: Wed May 09, 2007 10:16 am
Everah | Please use
file: test2.php
Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have a page which allows a user to add items to a listbox. When the form submits I want to capture all values from the listbox on a second page as an array so that I can save them to a table. I am currently using the request method however I am only capturing one of the values from the list box and cant' seem to find any examples on how to proceed. Any help will be appreciated.
Thank you,
Josh
The code for the two files is as follows:
file: test1.phpCode: Select all
<HTML>
<HEAD>
<TITLE>SDLC Input</TITLE>
<script language="JavaScript">
function AddItems()
{
var myForm = document.Form1; //Form Name
var mySel = myForm.sel1; // Listbox Name
var myOption;
myOption = document.createElement("Option");
myOption.text = document.getElementById("project_number").value; //Textbox's value
myOption.value = document.getElementById("project_number").value; //Textbox's value
mySel.add(myOption);
}
// begin list clear
function clearlistbox(lb)
{
for (var i=lb.options.length-1; i>=0; i--)
{
lb.options[i] = null;
}
lb.selectedIndex = -1;
}
</script>
</HEAD>
<body>
<FORM name="Form1" METHOD="POST" ACTION="test2.php">
<center><h3>Project Checklist</h3>
<hr>
</center>
<? // Project Number ?>
<tr><td>
<b>Project Number:</b>
</td><td>
<input type="text" size=6 id="project_number" name="project_number" value="" >
<align="center" valign="middle">
<input type="button" value="Add"
onclick="AddItems()">
<input type="button" value="Clear"
onclick="clearlistbox(sel1)" />
<select name="sel1" id="sel1" size="5" multiple="multiple" >
</select>
<a href=javascript:launchwin('proj_numbers.htm','Project_Numbers','height=300,width=600,scrollbars,resizable')>Project Codes</a>
</td></tr>
</table>
<center><INPUT TYPE=SUBMIT VALUE='<<<<<< SAVE >>>>>>>'></center>
</BODY>
</HTML>file: test2.php
Code: Select all
<?php
$sel1 = trim($_REQUEST['sel1']);
echo $sel1;
?>Everah | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]