Why is the value not passed to my controller page in codeigniter?
- by udaya
I am selecting state from country and city from state. This is my country select box:
<td width=""><select name="country" onChange="getState(this.value)" class="text_box_width_190">
<option value="0">Select Country</option>
<? foreach($country as $row) { ?>
<option value="<?=$row['dCountry_id']?>"><?=$row['dCountryName']?></option>
<? } ?>
</select></td>
This is my state select box:
<select name="state" id="state" class="text_box_width_190" >
<option value="0">Select State</option>
</select>
This is my city select box:
<td width=""><div id="citydiv"><select name="city" class="text_box_width_190">
<option>Select City</option>
</select></div></td>
This is my script:
<script type ="text/javascript">
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getState(countryId) {
var strURL="http://localhost/ssit/system/application/views/findState.php?country="+countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('statediv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getCity(countryId,stateId) {
var strURL="http://localhost/ssit/system/application/views/findCity.php?country="+countryId+"&state="+stateId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
This is my find state page:
<? $country=intval($_GET['country']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('ssit');
$query="Select dStateName,dState_id FROM tbl_state Where dCountry_id='1'";
$result=mysql_query($query);
?>
<select name="state" onchange="getCity(<?=$country?>,this.value)">
<option value="0">Select State</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['dState_id']?>><?=$row['dStateName']?></option>
<? } ?>
</select>
This is my find city page:
<? $countryId=intval($_GET['country']);
$stateId=intval($_GET['state']);
$link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('ssit');
$query="Select dCityName,dCity_id FROM tbl_city Where dState_id='30'";
$result=mysql_query($query);
?>
<select name="city">
<option>Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['dCityName']?></option>
<? } ?>
</select>
When I post a country, I can receive it but I can't receive my state and city. How to receive them?