Page 1 of 1

[solved] Obtaining multiple values from a list menu

Posted: Mon Oct 02, 2006 8:18 am
by hame22
Hi I have a form page containing a select menu (id = "salary") whereby the user can select multiple values.

The form data is then posted to my 2nd page.

What I am trying to do is then get this posted salary data, if I was only sending one value across I would enter $salary = $_POST['salary'] however what is the terminology when posting multiple values?

Thanks in advance

Posted: Mon Oct 02, 2006 8:31 am
by Rovas
You can send multiple data using POST or GET but you have to name your data differently ex data1, data2 i.e.

Code: Select all

$_POST['data1'] != $_POST['data2']
But try this code:

Code: Select all

//your code
echo "<select>";
echo "<option value='2.php' select='selected'>Default value</option>";
echo "<option  value='2.php?salary=1'>10000-20000</option>";
echo "<option value='2.php?salary=2'>21000-3000</option>";
echo "</select>"
//etc, etc, etc
//In the second page
if(is_numeric($_POST) && $_POST['salary']==2) 
{
//your code for that case
}

Posted: Mon Oct 02, 2006 8:42 am
by hame22
sorry i dont't think I explained that very well.....

what Iam trying to do is to send multiple values from ONE dropdown:

Code: Select all

<select name="salary" size="5" multiple="multiple">
              <option value="1">10,000</option>
              <option value="2">20,000</option>
              <option value="3">30,000</option>
            </select>
so this dropdown lets me select multiple values from it (not just the one)

What I am having trouble is assigning the multiple values on the 2nd page once it has been posted.

Posted: Mon Oct 02, 2006 9:00 am
by volka
try

Code: Select all

<select name="salary[]" size="5" multiple="multiple">

Posted: Mon Oct 02, 2006 9:55 am
by hame22
yeah that is spot on, just found the same answer myself, thanks!