PHP: Dropdown function like a button

I'm just wondering. Is there a way or a code that the dropdown/combobox in PHP will also like a button, have an action. My items in dropdown came from database then everytime I choose in the item in my dropdown I want it to have an action where it will reload the page, the same page..Currently, I'm using a button just to reload the page. But all I want is the dropdown will be the one who will reload the page.

Below is my Code.

Select Network: <select name="id">

<option value="<?php echo $get_ID; ?>"><?php echo $get_ID; ?></option>

<?php
include 'connect.php';

$q = mysql_query("select fldNetname from tblnetwork");



while ($row1 = mysql_fetch_array($q))
{
     if($get_ID != $row1[fldNetname])
        {
            echo "<option value='".$row1[fldNetname]."'>".$row1[fldNetname]."</option>";
        }
}
?>
</select>

Upvotes: 1

Views: 4770

Answers (3)

brunofitas
brunofitas

Reputation: 3083

<script>
    $("#selectBoxId").change(function () {
        window.location = document.URL + "?id="+ $("#selectBoxId").val();
    })
</script>

Upvotes: 0

Amar Banerjee
Amar Banerjee

Reputation: 5012

You can also do it in this way.

<select name="sweets" multiple="multiple" id="drop" onchange="send_value(this.value);" >
<option value="1">Chocolate</option>
<option selected="selected" value="2">Candy</option>
<option value="3">Taffy</option>
<option selected="selected" value="4">Caramel</option>
<option value="5">Fudge</option>
<option value="6">Cookie</option>
</select>

<script>
   function send_value(val)
   {
        window.location = "page.php?value="+val;
       // Here page.php is the page where you want to send the value it may be the name of same page.
   } 
</script>

Upvotes: 3

Harshal
Harshal

Reputation: 3622

yes you can perform actions by changing the drop downbox and behave like button.for that you need to use the jquery.

For example:

<script>
$("#drop").change(function () {
//do here what action you want to perform
})
</script>
<select name="sweets" multiple="multiple" id="drop">
<option>Chocolate</option>
<option selected="selected">Candy</option>
<option>Taffy</option>
<option selected="selected">Caramel</option>
<option>Fudge</option>
<option>Cookie</option>
</select>

Upvotes: 0

Related Questions