[eluser]rash[/eluser]
hello
i am new in php mvc, so can anyone tell me that how can i write the code for show another select menu box onchange the option of a select box without page refresh.
i tried some codes i.e.
this code is for view:
Code:
[removed][removed]
[removed]
$(document).ready(function()
{
$(".country").change(function()
{
var main_route_id=$(this).val();
var dataString = 'main_route_id='+ main_route_id;
$.ajax
({
type: "POST",
url: "<?php echo URL; ?>transport/ajax_city.php",
data: dataString,
cache: false,
success: function(html)
{
$(".city").html(html);
}
});
//alert(dataString);
});
});
</script>
<style>
label
{
font-weight:bold;
padding:10px;
}
</style>
<body>
<div style="margin:80px">
<label>Country :</label> <select name="country" class="country">
<option selected="selected">--Select Country--</option>
<?php
foreach($this->routelist as $key=>$value){
?>
<option value="<?php echo $value['main_route_id']; ?>"><?php echo $value['main_route']; ?></option>
<?php } ?>
</select> <br/><br/>
<label>City :</label> <select name="city" class="city">
<option selected="selected">--Select City--</option>
<?php
foreach($this->subroutelist as $key=>$value1){
?>
<option value="<?php echo $value1['route_id']; ?>"><?php echo $value1['destination']; ?></option>
<?php } ?>
</select>
on controller the code is:
Code:
public function student_transport_assign($student_id)
{
$student_id=$_POST['student_id'];
$this->view->username=$_POST['username'];
$this->view->mrlist=$this->model->mrList();
$main_route_id=$_POST['main_route_id'];
$this->view->routelist=$this->model->route();
$this->view->subroutelist=$this->model->subroute($main_route_id);
$this->view->render('transport/student_transport_assign');
}
and the model code is:
Code:
public function route()
{
return $this->db->select("SELECT * FROM main_route");
}
public function subroute()
{
echo $_POST['main_route_id'];
if($_POST['main_route_id'])
{
return $this->db->select("select route_id, destination, cost from route where main_route='$main_route_id'");
}
else
{
}
}
but it is not working...
pls help me.......