Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem with this plugin is it cannot handle the onchange() event because of that we are mostly irritate. So, here is the solution for that..</p> <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;script src="jquery.selectbox-0.5.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function() { $('.items').selectbox(); $('#country_input').blur(function(){ setTimeout(function(){ var e = document.getElementById("country"); var countryCode = e.options[e.selectedIndex].value; getState('state',countryCode); },500) }); }); &lt;/script&gt; &lt;script type="text/javascript"&gt; function getState(state_id, countryCode) { var option_str = document.getElementById(state_id); option_str.length=0; option_str.options[0] = new Option('Select State',''); option_str.selectedIndex = 0; //write your code to get state list with the use of "countryCode" var state_arr = stateListArray; //assume "stateListArray" is an array which is holding list of states for (var i=0; i&lt;state_arr.length; i++) { option_str.options[option_str.length] = new Option(state_arr[i],state_arr[i]); } $('#state').parent().children(':not(#state)').remove(); $('#state').selectbox(); } &lt;/script&gt; &lt;p&gt; &lt;select id="country" class= "items" name ="country"&gt; &lt;option value="countryCode"&gt;Country Name&lt;/option&gt; &lt;/select&gt; </code></pre> <p></p></p> <p> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload