Check out the Jquery Chosen Plugin page and demos. It's a really useful tool.
I'm currently facing an issue with a 2 stage input form for collecting location information. The first select menu is for countries. When a country is selected, the 2nd input field should only display options related to that country. Pretty neat!
You can see a live demo of my issue here:
Although the ajax call is working fine, the styling gets lost once the 2nd field data is returned. =(
As per the plugin guidelines,
The select menu must be placed within a specific HTML structure
<select data-placeholder="Select City" class="chzn-select" style="width:350px;" tabindex="2" name="city">
<? while($row=mysql_fetch_array($result)) { ?>
<option class="active-result option"
style="padding: 5px 0px 5px 0px; font-family:arial; font-size:12px;"
><?=$row['city']?></option>
<? } ?>
</select>
This code technically should work but it's not. Any suggestions on how to maintain the styling after the ajax call?
Here is the PHP page that is being returned
<!--//---------------------------------+
// Developed by Roshan Bhattarai |
// http://roshanbh.com.np |
// Contact for custom scripts |
// or implementation help. |
// <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="eb8e868a8287c6858e9b8a8782898492dbdbdcab928a838484c5888486">[email protected]</a> |
//---------------------------------+-->
<?
#### Roshan's Ajax dropdown code with php
#### Copyright reserved to Roshan Bhattarai - <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcd2d9ccddd0d5ded3c58c8c8bfcc5ddd4d3d392dfd3d1">[email protected]</a>
#### if you have any problem contact me at http://roshanbh.com.np
#### fell free to visit my blog http://php-ajax-guru.blogspot.com
?>
<? $country = $_GET['country'];
$link = mysql_connect("SNIP");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('SNIP');
$query="SELECT city FROM location WHERE country='$country' ORDER BY `city` ASC";
$result=mysql_query($query);
?>
<div class="x">
<br>
<select data-placeholder="Select City" class="chzn-select" style="width:350px;" tabindex="2" name="city">
<? while($row=mysql_fetch_array($result)) { ?>
<option class="active-result option"><?=$row['city']?></option>
<? } ?>
</select>
</div>