Open your form which is in Yournamespace/Modulename/Block/Adminhtml/Modulename/Edit/Tab/Form.php then add below fields
$country = $fieldset->addField(‘country’, ‘select’, array(
‘name’ => ‘country’,
‘label’ => ‘Country’,
‘values’ => Mage::getModel(‘adminhtml/system_config_source_country’) ->toOptionArray(),
‘onchange’ => ‘getstate(this)’,
));
$fieldset->addField(‘state’, ‘select’, array(
‘name’ => ‘state’,
‘label’ => ‘State’,
‘values’ => Mage::getModel(‘modulename/modulename’)
->getstate(‘AU’),
));
/*
* Add Ajax to the Country select box html output
*/
$country->setAfterElementHtml(“<script type=”text/javascript”>
function getstate(selectElement){
var reloadurl = ‘”. $this
->getUrl(‘modulename/adminhtml_modulename/state’) . “country/‘ + selectElement.value;
new Ajax.Request(reloadurl, {
method: ‘get’,
onLoading: function (stateform) {
$(‘state’).update(‘Searching…’);
},
onComplete: function(stateform) {
$(‘state’).update(stateform.responseText);
}
});
}
</script>“);
Now Create State Action in modulenamecontroller.php file which will be like this
public function stateAction() {
$countrycode = $this->getRequest()->getParam(‘country’);
$state = “<option value=”>Please Select</option>”;
if ($countrycode != ”) {
$statearray = Mage::getModel(‘directory/region’)->getResourceCollection() ->addCountryFilter($countrycode)->load();
foreach ($statearray as $_state) {
$state .= “<option value=’” . $_state->getCode() . “‘>” . $_state->getDefaultName() . “</option>”;
}
}
echo $state;
}