1

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
  • I'm sorry, what do you mean by "passed through a query string"? As in a mysql query? and what do you mean by "without a button"? Are you wanting to use ajax to pass the data back to the server? Commented Sep 4, 2009 at 6:26

3 Answers 3

2
<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 />';
    }
}
?>
Sign up to request clarification or add additional context in comments.

4 Comments

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 - 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.
I actually had to removed the brackets in order for it to work.
@Nate Shoffner - are you using a multi or normal select?
1

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>

Comments

0

Without a button:

<form method="get">
<select multiple="multiple" name="things[]" onchange="this.form.submit()">
...
</select>
</form>

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.