Jump to content

Variables in a Multiple select drop down


scrbowler

Recommended Posts

You can do it with an array I think, it has something to do with putting "[]" somewhere in the input element... then it will become a sub-array of the $_POST array.

 

That's all I can think of, at any rate. I've never done it before so I can't really help.

You need to create an array for these values, so here is an example.

 

HTML

<form>
   <select name="choices[]" multiple="multiple">
         <option>...</option>
         <option>...</option>
         <option>...</option>
         <option>...</option>
         <option>...</option>
         <option>...</option>
   </select>
</form>

 

Now when they submit the form, all the selected values will be in the array $_POST['choices']

Just grab them straight from the array. From the HTML example I posted above, to get the first value you would use choices[0], and so on.

 

Or you could use a foreach loop, it all depends on what your trying to do. So if this doesn't help you, explain more.

I've been giving this the ole college try and nothing seems to work for what I want when it comes to assigning a variable to the results of the form.

 

As you see in the code below I have a couple of efforts to make the variable available to the array list but I can't get it to post using the examples below.  Any help in assigning the variables to the choices will be greatly appreciated.  I'm trying to use the variables $driver1, $driver2 .... and so forth for the 5 selections from the form.

 

thanks

Steve

 

<form name="entry" method="post" action="<? echo $PHP_POST; ?>">
   <select name="choices[]" multiple="multiple">
         <option><input type="radio" name="#48 Jimmie Johnson" value="48" />#48 Jimmie Johnson</option><br>
         <option><input type="radio" name="#24 Jeff Gordon" value="24" />#24 Jeff Gordon</option><br>
         <option><input type="radio" name="#07 Clint Bowyer" value="107" />#07 Clint Bowyer</option><br>
         <option><input type="radio" name="#17 Matt Kenseth" value="17" />#17 Matt Kenseth</option><br>
         <option><input type="radio" name="#5 Casey Mears" value="5" />#5 Casey Mears</option><br>
         <option><input type="radio" name="#20 Tony Stewart" value="20" />20 Tony Stewart</option><br>
         <option><input type="radio" name="#77 Sam Hornisch Jr." value="77" />#77 Sam Hornisch Jr.</option><br>
         <option><input type="radio" name="#31 Jeff Burton" value="31" />#31 Jeff Burton</option><br>
         <option><input type="radio" name="#99 Carl Edwards" value="99" />#99 Carl Edwards</option>
   </select>
<input type="submit" name="submit" value="Send" />

</form>
<?

$ID=array($_POST, $choices, "choices[2]", "choices[3]", "choices[4]"); //trying 3 diff attempt for values but no luck
for($count = 0; $count < sizeof($ID); $count++) { 
$IDarray[]=$ID[$count]; 
} 
foreach($IDarray as $key => $val) { 
print("$key -- $val<br />"); 
} 


?> 

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.