bepster
bepster

Reputation: 93

Javascript onchange select boxes

So I have a drop down box that posts to the page on a submit button.

I am trying to remove the submit button and make it so it posts when you change the drop down as its a much better way to work!

The value = "submit_button" and it gets picked up by:

// Check if form has been submited
if ($_POST['submit_button'])
{

// If form has been submited set $newCookieValue variable, set cookie and refresh webpage
$newCookieValue=$_POST['dbselector'];

The code I am trying to use is:

<form>
    <select name="dbselector" onchange="this.form.submit()" style="margin-left:0.5em;">
    <option value="option_1" selected="selected">option_1</option>
    <option value="option_2">option_2</option>
    </select>
<noscript><input type="submit" value="submit_button"/></noscript>
</form>

When I change the drop down from option 1 to option 2 it reloads the page but I don't think its posting the values as I can check the values by adding this into the top of the page:

<br> <?php var_dump($_POST['dbselector']) ?> 
<br> <?php var_dump($_POST['submit_button'])?> 

and they both return NULL?????

Upvotes: 0

Views: 47

Answers (1)

Spencer Wieczorek
Spencer Wieczorek

Reputation: 21565

You need to state in your form that you are using POST via method in order to tell the form which HTTP method to use:

<form method="post">
   ...
</form>

Upvotes: 1

Related Questions