Hi I want to implement child parent combo box(country state like if we select any country the state combo box should be populated according to selected country) in my form with jquery. Please give any suggestion how to implement this Thanks
+1
A:
Well, attach a function on the change event of the country combo box and fetch the html from the AJAX or similar. Then populate the child combo box.
For example
$("#parentbox").change(function() {
var myval =$("#parentbox").val();
// Fetch the content from database or similar
$("#childbox").html(newhtml);
}
Starx
2010-08-20 07:16:25
thanks for answer..but actually am working with zend framework and am using simple html form instead of zend form.
2010-08-20 07:21:39
What is the purpose of using $("#childbox").empty(); before .html()?
Chris
2010-08-20 08:40:56
How corresponding states will populated according to countryPlease explain how to fetch content from database.
2010-08-20 08:54:43
@swati-vyas: methods might be multiple, through ajax request or JSON content....
Starx
2010-08-20 09:26:43
.html() will clear the content before populating new data. .empty() is redundant for that purpose.
Chris
2010-08-20 11:03:09
@chris, Oh yeah.. Slip off my mind :) corrected
Starx
2010-08-20 12:27:30
A:
This code iterates through an array, and populates another select box (#targetBox) based on your selection in #sourceBox.
$(document).ready(function(){
$('#sourceBox').change(function(){
var options = "";
for (var i = 0; i < locations.length; i++){
options += '<option>'
+ locations[i][$('#sourceBox option:selected').text()]
+ '</option>';
}
$('#targetBox').html(options);
});
});
Chris
2010-08-20 07:21:52