Welcome Guest, Not a member yet? Register   Sign In
ajax and CI
#1

[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>
&lt;?php
//how do i echo the value from display????
?&gt;
#2

[eluser]nuttynibbles[/eluser]
okay mayb my explanation is too long and confusing.

let me explain again:
basically what i need to do is to populate the sub-category dropdown list based on the 1st dropdown list.

i managed to get ajax to work and echo it in the controller. for my view file, i have a <div id="display"></div> which will display the echo results.

but, instead of echo and display into the <div> in the view file, i would like to capture the value and pass it to a php function in the same view file.

controller
Code:
function populatelist()
    {
        $dropdown=$_POST['postdata'];
        echo $dropdown;
        
    }

view
Code:
<div id="display"></div>
&lt;?php
//i would like to capture the value into php
?&gt;
#3

[eluser]nuttynibbles[/eluser]
solved!!




Theme © iAndrew 2016 - Forum software by © MyBB