bepster bepster - 1 year ago 80
Javascript Question

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

The code I am trying to use is:

<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>
<noscript><input type="submit" value="submit_button"/></noscript>

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?????

Answer Source

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">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download