jQuery Select box is very tedious to apply CSS again in the drop down while ajax call. I did R&D for apply CSS and value again in drop down during jQuery Ajax call.
I have presenting one demo example for How to change drop down of state based on country selection.
Step1 :Create simple HTML drop down
Step2: jQuey Select box call selectbox() function to the drop down. It will apply custom CSS in particular drop down.
While Ajax call response of Ajax as you need to prepare below.Call your query or prepare data for sate drop down based on your selected country
Ex. ajax.php
After Ajax response you need to detach drop down of state,It will be remove values and remove drop-down select box CSS and then populate value in that state drop down using val() function.You need to again attach select box in that drop down. So select box jQuery CSS will be apply in Ajax call again.
Demo Link of jQuery Selectbox https://code.google.com/p/select-box/
I have presenting one demo example for How to change drop down of state based on country selection.
Step1 :Create simple HTML drop down
Step2: jQuey Select box call selectbox() function to the drop down. It will apply custom CSS in particular drop down.
$("#country_id").selectbox(); $("#state_id").selectbox();Change state value based on country selection.I have used ajax call for change state value based on country selection. jQuery select-box provide us onChange event for select value based on selection.You need to tack care for attach and detach method of jQuery select box plugin.
While Ajax call response of Ajax as you need to prepare below.Call your query or prepare data for sate drop down based on your selected country
Ex. ajax.php
$state_str =''; $state_str.= ''; $state_str.= ''; $state_str.= ''; $state_str.= ''; echo $state_str;Return above option in Ajax response.
After Ajax response you need to detach drop down of state,It will be remove values and remove drop-down select box CSS and then populate value in that state drop down using val() function.You need to again attach select box in that drop down. So select box jQuery CSS will be apply in Ajax call again.
$("#country_id").selectbox({ onOpen: function (inst) { //console.log("open", inst); }, onClose: function (inst) { //console.log("close", inst); }, onChange: function (val, inst) { $.ajax({ type: "GET", data: {country_id: val}, url: "ajax.php", success: function (data) { $("#state_id").selectbox('detach'); $("#state_id").val(value); $("#state_id").selectbox('attach'); } }); }, effect: "slide" });
Demo Link of jQuery Selectbox https://code.google.com/p/select-box/
ReplyDeleteI get a lot of great information from this blog.
Chip Level Training in Hyderabad
Thanks for sharing this valuable information to our vision. You have posted
ReplyDeletea trust worthy blog keep sharing.
Chip Level Training in Hyderabad
it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly
ReplyDeleteChip Level Training in Hyderabad
Thanks for sharing this valuable information to our vision. You have posted
ReplyDeletea trust worthy blog keep sharing.
Laptop service center in Hyderabad