Dropdown made using Bootstrap
<form id="search" action="" method="post" >
<div class="dropdown">
<button data-toggle="dropdown" id="dropdownMenu1" type="button" class="btn btn-default dropdown-toggle">Fixed <span class="caret"></span></button>
<ul aria-labelledby="dropdownMenu1" role="menu" class="dropdown-menu">
<li role="presentation"><a href="#" tabindex="-1" role="menuitem">Florida</a></li>
<li role="presentation"><a href="#" tabindex="-1" role="menuitem">Texas</a></li>
<li role="presentation"><a href="#" tabindex="-1" role="menuitem">Washington</a></li>
<li role="presentation"><a href="#" tabindex="-1" role="menuitem">New York</a></li>
<li role="presentation"><a href="#" tabindex="-1" role="menuitem">Ohio</a></li>
</ul>
</div>
</form>
jQuery to keep dropdown option selected
var jQee = jQuery.noConflict();
jQee(".dropdown-menu li").click(function(){
var selText = jQee(this).text();
jQee(this).parents('.dropdown').find('.dropdown-toggle').html(selText+' <span class="caret"></span>');
//jQee('#search').submit();
});
HTML Dropdown
<select onchange="form.submit()" name="template">
<option value="F" selected="true">Florida</option>
<option value="T">Texas</option>
<option value="W">Washington</option>
<option value="N">New York</option>
<option value="O">Ohio</option>
</select>
For the above dropdown, I am fetching the option value
based on user selection.
While doing it with Bootstrap
, I am able to keep the the dropdown value selected
, but as I am using it with PHP
, I also need the value in $_POST
variable in order to execute SQL
query and display results based on what value is selected from dropdown.
How can I achieve it?