[eluser]nuttynibbles[/eluser]
i need to pass some value through ajax and CI. basically my problem is, i have 2 dropdown list. the 2nd dropdown list will display items based on the selection of 1st drop down list. what happen is I would select an item from the 1st drop down list. based on the onchange result, i would extract this value and pass it to an ajax function like this:
Code:
<select class="form_select" name="make" id="make"><option selected value=''>--Select--</option><option value="1">item 1</option><option value="2">item 2</option>...</select>
. currently the data would be display in <div id="display"></div> in the view file. but i would like to take this value n pass it to the 2nd dropdown list and populate it in the same view file in PHP. how do i extract the value from div into php??? or is there a better way around it?
here is my Ajax function:
Code:
function ajaxpost(siteurl,param,tag)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ("Browser does not support HTTP Request");
return;
}
var strurl=siteurl;
var param='postdata='+param;
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById(tag)[removed]=xmlHttp.responseText;
}
}
xmlHttp.open("POST",strurl,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", param.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(param);
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e){
// Internet Explorer
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
here is my controller:
Code:
function populatelist()
{
$dropdown=$_POST['postdata'];
echo $dropdown;
}
here is my view:
Code:
<div id="display"></div>
<?php
//how do i echo the value from display????
?>