[eluser]Circus-Killer[/eluser]
Hey there.
I am currently working on the registration section of a website. there are two select boxes. one that will allow you to choose a region, another to choose a department. everytime a region is selected/changed, the department list must reload from the database the list of departments in that specific region. i have it running in firefox with no problem, but when i try run it in ie7 i get php errors.
here is the ajax script:
Code:
function ajaxFunction(){
document.registration.deps.disabled = false;
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementById('dep_options')[removed]=ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "http://localhost/index.php/ajax/get_deps/" + document.registration.region.options[document.registration.region.selectedIndex].value, true);
ajaxRequest.send(null);
}
and the codeigniter controller it calls:
Code:
<?php
class Ajax extends Controller{
function get_deps(){
$this->load->model('ajax_model');
$deps = $this->ajax_model->get_deps($this->uri->segment(3));
$response = '<select name="deps">';
if ($deps->num_rows() > 0){
foreach ($deps->result() as $row){
$response = $response.'<option value="'.$row->id.'">'.$row->name.'</option>';
}
}
else{
$response = $response.'<option value="">--</option>';
}
$response = $response.'</select>';
echo $response;
}
}
?>
and the model:
Code:
<?php
class Ajax_model extends Model{
function __construct(){
parent::Model();
$this->load->database();
}
function get_deps($region_id){
$query = $this->db->query("SELECT id, name
FROM departments
WHERE region_id = ".$region_id);
return $query;
}
}
?>