Social Engine Zend Framework - Dynamic Ajax dropdown for Country / State / City
I am working with Social Engine which is based on Zend Framework and Smarty Templates.
I need to make custom functionality for profile page, where I need Ajax based Dynamic Country / State / City sel开发者_JAVA百科ections like
Dropdown for Country -> on selection of some country, State will display belonging to selected country and State selection -> related Cities will display. I have separate tables for my country/state and city.
Anybody can help us or can provide some reference / examples for the same?
I don't know, how to make Ajax calls and render my views with this !
Regards !
See code below:
giving code from my project loads segment, sub-segments of ship type. same as country ,state
first make parent drop down as usual like this :
<?php
echo $this->formSelect('segment','none',array('class' => 'select-advanced', 'width' => '250'),$this->arrInput['shiptype']);
?>
here arrInput['shiptype'] is from controllar
make a div for child drop down on ur form
Now put below jquery code on ur form:
<script>
var base_path = "<?php echo $this->baseUrl();?>/";
$('#segnam').change(function()
{
var segId=document.getElementById('segment').value;
$.ajax({
url: base_path + "search/subseg/",
data: "segId="+segId,
type: 'GET',
success: function (resp) { document.getElementById('subsegdiv').innerHTML=resp;},
error: function(e){ alert('Error: '+e); }
});
});
</script>
now for child drop dowm in yor controllar make a action :
public function subsegAction()
{
$request = $this->getRequest();
$objShiptype = new Shiptype();
$segId=$request->getParam('segId');
$SubSegArr=$objShiptype->getSubSegment($segId);
$this->_helper->layout->disableLayout();
$this->getResponse()->setHeader('Content-Type', 'text/javascript');
$this->view->subseg=$SubSegArr;
}
now make a view for above action:
make html drop down (child) using html take data from subseg controller
here refer segment = country subseg = state
for city follow same make a action and view and jquery code again.
If not clear u are free to ask. I have donw this task. It's tricky :)
精彩评论