views:

1040

answers:

4

I have a drop down list that has options that need to be passed through a query string. How would I go about doing this? Also, would anyone be able to list a way to do this both using a button and without using a button? Thank you!

+1  A: 
<form method="get">
<select multiple="multiple" name="things[]">
...
</select>
<input type="submit" value="submit"/>
</form>

<?php    
if(isset($_GET['things'])) {
    foreach($_GET['things'] as $thing) {
       echo $thing . '<br />';
    }
}
?>
karim79
Thank you. Man you've helped me a lot. haha
Nate Shoffner
I'm still unclear as to what the problem was that this solved. was it the use of the brackets in the name to make it an array?
Anthony
@Anthony - he said 'options' so I figured he meant a multi-select and he was wondering how to get the array of selected options to the server, the gotcha being the [] after the select's name attribute, and knowing that turns $_GET['things'] into an array.
karim79
I actually had to removed the brackets in order for it to work.
Nate Shoffner
@Nate Shoffner - are you using a multi or normal select?
karim79
Normal, I changed it.
Nate Shoffner
A: 

Without a button:

<form method="get">
<select multiple="multiple" name="things[]" onchange="this.form.submit()">
...
</select>
</form>
Jani Hartikainen
To be more accessible and backward compatible, I'd go with:`<select multiple="multiple" name="things[]" onchange="this.form.submit()"><noscript><input type="submit" />`
Anthony
erp...<select multiple="multiple" name="things[]" onchange="this.form.submit()"><noscript><input type="submit" /></noscript>
Anthony
+1  A: 

Based on Jani's response, are you wanting to have the form submit without a button but still have a backup button if the user doesn't have javascript? You can use noscript to cover that:

<form action="script.php" method="get">
     <div>
     <select name="options" onchange="this.form.submit()">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
     </select>
     <noscript>
          <input type="submit" value="Go!" />
     </noscript>
     </div>
</form>
Anthony
A: 

Hi,

I want to filter the database value using the dropdown list option, how to proceed in php.