This is my index.php
<form class="form-horizontal well bar" action="<?php echo base_url();?>search" method="post" role="form">
<div class="col-md-2">
<div class="form-group">
<div class="col-md-12">
<select class = "course" name = "course_offrd-name[]" onchange="" id = "course_offrd_name" class = "form-control">
<option value="">Select</option>
<?php
foreach($coursedata as $val)
{
?>
<option value="<?php echo $val->course_offrd_name;?>">
<?php
echo $val->course_offrd_name;
?>
</option>
<?php
}
?>
</select>
</div>
</div>
</div>
</form>
This is Javascript code in index.php
page
<script>
$(document).ready(function () {
$("select.course").change(function () {
var selectedCourse = $(this).children("option:selected").val();
alert("You have selected the course - " + selectedCourse);
});
});
</script>
this is ajax code in index.php
page
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".course").on('change', function()
{
var level = $(this).val();
if(level)
{
$.ajax ({
type: 'POST',
url: base_url+"home/search",
data: {course_offrd_name: selectedCourse},
success : function(htmlresponse)
{
$('#opt_lesson_list').html(htmlresponse);
console.log(htmlresponse);
}
});
}
});
});
</script>
This is my controller
public function search()
{
$id = $this->input->post('course_offrd_name');
$data['result'] = $this->front->get_data_wheree($id);
$this->load->view('home/search', $data);
}
This is my model
function get_data_wheree($table)
{
$this->db->select('course_offrd_name, collg_id');
$this->db->group_by('course_offrd_name');
return $this->db->get('tbl_course_offered')->result();
}
This is search.php
file ie here i want to display the selected dropdown option
<?php
foreach($result as $row)
{
echo $row['course_offrd_name'];
}
?>
Satabase table name is tbl_course_offered
it has collg_id and course_offrd_name
column.
My dropdowndown option is comming from course_offrd_name
Problems: I have page index.php
and I have two dropdown option say two courses science and Maths.
If i selected science from downdown and submit the button it redirect the page to search.php and should display science on search.php page.
I have used ajax code for that trying to send the data to controller and then to search.php but not getting the result.
My dropdown option is actually not able to send inside the controller search function and then to search.php.
What is the issue in the code?
my dropdown option send is failed from ajax to controller only and then to controller to search.php
.
I m using Codeigniter3
why i m not able to send the dropdown option from index.php
to controller and then to search.php
page?
why i m not getting the post data in controller?
If any file is required will help you.