Jump to content

Passing multiple values


thomashw

Recommended Posts

I have the "options" of a "select" form being populated by a 'for' loop after querying a database to see how many options are there for the specific page.

 

What I want to do is pass more than one value depending on which option the user selects. I already have one value being passed by the means of "<option name="name" value="value"..." but I'd like to pass another value as well.

 

I tried adding a "hidden" input in the form loop to be populated as well, but this just passes all the values in the database - not just the one corresponding to what the user selected.

 

Anyone have any good ideas for passing more than one value depending on what a user selects in a drop-down box? :)

Link to comment
https://forums.phpfreaks.com/topic/97075-passing-multiple-values/
Share on other sites

You could separate each value by a delimiter, then explode() it when you use the data.

 

So, something like this:

<select>
   <option value="value1-value2-value3">
   <option value="value1-value2">
</select>

 

Give more information on what values your trying to pass, and why you need the multiple values. There could be a better way.

Working with an option/select box is same as working with checkboxes :)

 

just define the name with the array square brackets.

 

here is a sample I use to demonstrate (modified with select/option)

 

<?php

if($_SERVER['REQUEST_METHOD']=='POST')
{
if(isset($_POST['cb']))
{
	$cb=implode(',',$_POST['cb']);
}
echo "cb = '$cb'<BR>";
if(isset($_POST['sb']))
{
	$sb=implode(',',$_POST['sb']);
}
echo "sb = '$sb'<BR>";
}

?>    
  <form method="POST">
  <select name="sb[]" multiple="true">
  <option value="0">Zero</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
  </select>
  0<INPUT TYPE='checkbox' name='cb[]' value='0'>  
  1<INPUT TYPE='checkbox' name='cb[]' value='1'>  
  2<INPUT TYPE='checkbox' name='cb[]' value='2'>  
  3<INPUT TYPE='checkbox' name='cb[]' value='3'>  
  4<INPUT TYPE='checkbox' name='cb[]' value='4'>
  <INPUT type="submit">
  </FORM>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.