Welcome Guest, Not a member yet? Register   Sign In
load second dropdown values based on the first (how to implement AJAX)
#5

[eluser]bhakti.thakkar[/eluser]
thanks for that help. i downloaded the .js file and included it. but nothing seems to work. may be i am missing somthing. in the mean while i have tired to do the below. can check what is the problem. i am getting js error : "the requested url not found on the server".

but i have done the proper point to the controller/funtion_name/parameter

certificate_confirm.php

Code:
<?$this->load->view('header');?>
[removed]
    function getHTTPObject(){
          if (window.ActiveXObject)
              return new ActiveXObject("Microsoft.XMLHTTP");
          else if (window.XMLHttpRequest)
              return new XMLHttpRequest();
          else {
              alert("Your browser does not support AJAX.");
              return null;
          }
      }

    function LoadSubprograms(Project_ID){
        httpObject = getHTTPObject();
        if (httpObject != null) {
            httpObject.open("POST", "<?=base_url()?>certificates/get_subprograms/"+Project_ID, true);
            httpObject.send(null);
            httpObject.onreadystatechange = setOutput;
        }
    }
    
    function setOutput(){
        if(httpObject.readyState == 4){
            alert();
            alert(httpObject.responseText);
            document.getElementById('outputText').value = httpObject.responseText;
        }
    }
[removed]


<h2>Request a certificate</h2>
<TABLE width="100%" class="table" cellpadding=3 cellspacing=1>
&lt;form name="mainform" method=post&gt;
<TR>
    <TD width="20%" class="tdheader">Projects</TD>
    <TD class="datatd"><select name="Project_ID" id="Project_ID" >
        &lt;? foreach($query->result() as $row) { ?&gt;
            <option name="Project_ID" value="&lt;?=$row->Project_ID?&gt;">&lt;?=$row->Project_ID?&gt;</option>
        &lt;? } ?&gt;
    </select></TD>
</TR>
<TR>
    <TD class="tdheader">Subprogram</TD>
    <TD class="datatd"><span id="outputText"></span></TD>
</TR>
<TR>
    <TD class="tdheader">Certificate type</TD>
    <TD class="datatd">
    <select name="CertificateType">
        <option value="1">Transaction certificate</option>
        <option value="2">Import / Transaction certificate</option>
    </select></TD>
</TR>
<TR>
    <TD colspan="2">
    <ul id="logout_list">
    <li>&lt;?php echo anchor('logout/logout_routine', "Ok");?&gt;</li>
    <li><a href="&lt;?php echo site_url()?&gt;" class="lbAction" rel="deactivate">&lt;?="Cancel";?&gt;</a></li>
</ul></TD>

</TR>
&lt;/form&gt;
</TABLE>


certificates.php (Controller)
Code:
&lt;?php

class Certificates extends Controller {

    function __construct()
    {
        parent::Controller();
        if (!$this->site_sentry->is_logged_in()) {redirect('login');}
    }

    // --------------------------------------------------------------------

    function index()
    {
        $data['page_title'] = "Request Certificate";

        $this->load->view('certificates/certificate_confirm', $data);
    }

    // --------------------------------------------------------------------

    function logout_routine()
    {
        $this->session->sess_destroy();
        redirect('logout');
    }

    // --------------------------------------------------------------------

    function reqcertificate()
    {
        $data['page_title'] = "Request certificate";
        $this->load->model('projects_model');
        $offset = (int) $this->uri->segment(3, 0);
        $data['query'] = $this->projects_model->getProjects($offset, 5000);
//        $data['subp'] = $this->projects_model->getSubprograms('4233');


        $this->load->view('certificates/certificate_confirm', $data);
    }

    function get_subprograms($Project_ID)
{
        $this->load->model('projects_model');
        $subprog_query = $this->projects_model->getSubprograms($Project_ID);
//        print_r($subprog_query);
        return $subprog_query;    
    }

}
?&gt;

project_model.php

Code:
function getSubprograms($Project_ID)
    {

        $this->db->select('Subprogram_ID , dbo.uf_parmsel_subprogramname_of_subprogram(Subprogram_ID) AS SubprogramName ');
        $this->db->where('Project_ID', $Project_ID);
        
        $res= $this->db->get('Project_Subprogram_T');
              echo "<select id='Subprogram_ID' name='Subprogram_ID'>";
              foreach ($res->result() as $row){
                  echo '<option value="'.$row->Subprogram_ID.'">'.$row->SubprogramName.'</option>';
              }
              echo "</select>";
    }


Please please help me. i am going nuts from past 24 hrs. also i have attached the onchangeevent to the dd which is not gettig pasted : onChange="LoadSubprograms(this.value)"
<select name="Project_ID" id="Project_ID">
&lt;? foreach($query->result() as $row) { ?&gt;
<option name="Project_ID" value="&lt;?=$row->Project_ID?&gt;">&lt;?=$row->Project_ID?&gt;</option>
&lt;? } ?&gt;
</select>


Messages In This Thread
load second dropdown values based on the first (how to implement AJAX) - by El Forum - 10-22-2008, 03:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB