I have a dependent drop down that get the category on the first drop down and should get the subcategory on the second drop down but the subcategory drop down isn't populated. I have something like this in my Model:
public function category()
{
$response = array();
$this->search(array(), 'date_created');
$this->db->select('*');
$query = $this->db->get('categories');
$response = $query->result_array();
return $response;
}
public function sub_category($parent_id)
{
$query = $this->db->get_where('sub_categories', array('parent_id' => $parent_id));
return $query->result_array();
}
And then something like this on my Controller:
public function edit_product($id)
{
$data['title'] = 'Update Product';
$this->load->view('../admin/template/admin_header');
$products = new Admin_model;
$data['products'] = $products->edit_product($id);
$data['category'] = $this->Admin_model->category();
$data['subcategory'] = $this->Admin_model->sub_category($data['products']->category_id);
$this->load->view('../admin/template/admin_topnav');
$this->load->view('../admin/template/admin_sidebar');
$this->load->view('../admin/products/manage_product', $data);
$this->load->view('../admin/template/admin_footer');
}
function get_subcategory()
{
if ($this->input->post('parent_id')) {
echo $this->Admin_model->get_subcategory($this->input->post('parent_id'));
}
}
public function insert_product()
{
$productData = array();
if ($this->input->post('productData')) {
$this->form_validation->set_rules('category_id', 'Category', 'required');
$this->form_validation->set_rules('sub_category_id', 'Sub Category', 'required');
$this->form_validation->set_rules('product_name', 'Product Name', 'required');
$this->form_validation->set_rules('department', 'Department', 'required');
$this->form_validation->set_rules('description', 'Description', 'trim|required');
$this->form_validation->set_rules('status', 'Status', 'required');
if ($this->form_validation->run() == true) {
$ori_filename = $_FILES['product_image']['name'];
$update_image = time() . "" . str_replace(' ', '-', $ori_filename);
$config = [
'upload_path' => './images/products',
'allowed_types' => 'gif|jpg|png',
'file_name' => $update_image,
];
$this->load->library('upload', $config);
if (!$this->upload->do_upload('product_image')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view(base_url('admin/products'), $error);
} else {
$image = $this->upload->data('file_name');
$productData = array(
'category_id' => $this->input->post('category_id'),
'sub_category_id' => $this->input->post('sub_category_id'),
'product_name' => $this->input->post('product_name'),
'department' => $this->input->post('department'),
'description' => $this->input->post(htmlentities('description')),
'status' => $this->input->post('status'),
'upload_path' => $image
);
$img = new Admin_model;
$img->insert_product($productData);
$this->session->set_flashdata('status', 'Package InsertedSuccesfully');
redirect(base_url('admin/products'));
}
}
}
$data['title'] = 'Insert Product';
$data['category'] = $this->Admin_model->category();
$data['subcategory'] = $this->Admin_model->get_subcategory();
$this->load->view('../admin/template/admin_header');
$this->load->view('../admin/template/admin_topnav');
$this->load->view('../admin/template/admin_sidebar');
$this->load->view('../admin/products/manage_product', $data);
$this->load->view('../admin/template/admin_footer');
}
And then the view:
<div class="form-group">
<label for="" class="control-label"> Category</label>
<select name="category_id" id="category" class="custom-select select">
<option value="">Select Category</option>
<?php
foreach ($category as $row) {
echo '<option value="' . $row['id'] . '"';
if (isset($products) && $row['id'] == $products->category_id) {
echo ' selected';
}
echo '>' . $row['category'] . '</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="" class="control-label">Sub Category</label>
<select name="sub_category_id" id="subcategory" class="custom-select select">
<option value="">Select Sub Category</option>
<?php
foreach ($subcategory as $row) {
echo '<option value="' . $row['id'] . '"';
if ($row['id'] == $products->sub_category_id) {
echo ' selected';
}
echo '>' . $row['sub_category'] . '</option>';
}
?>
</select>
</div>
And here's the script. I'm not really familiar at AJAX so i tried to ask and get answers here which helps me progress but I still can't populate the subcategory drop down.
<script type="text/javascript">
$(document).ready(function() {
$('#category').change(function() {
var parent_id = $('#category').val();
console.log(parent_id)
if (parent_id != '') {
$.ajax({
url: "<?php echo base_url(); ?>admin/get_subcategory",
method: "POST",
data: {
parent_id: parent_id
},
success: function(data) {
$('#subcategory').html(data);
console.log(data)
}
});
} else {
$('#subcategory').html('<option value="">Select Category First</option>');
}
});
});
Also, here's what I get in the console
The result from $this->Admin_model->sub_category(...) is an array.
echo works on string values only, which is why you're getting the error. You'll need to loop over the result array (in admin/get_subcategory) and print the values one by one. Also surround each value with an <option> tag so the result can be placed in the select box without further modification:
public function get_subcategory() {
if ($this->input->post('parent_id')) {
$subcategories = $this->Admin_model->sub_category($this->input->post('parent_id'));
foreach ($subcategories as $subcategory) {
echo '<option value="'.$subcategory['id'].'">'.$subcategory['sub_category'].'</option>';
}
}
}
Related
In my Laravel-5.8, I have this code:
public $filters = [
"all" => "all",
"logged_in" => "logged in users",
"not_logged_in" => "not logged in users",
];
public function user_logs($id = "")
{
$userCompany = Auth::user()->company_id;
$userEmployee = Auth::user()->employee_id;
$userId = Auth::user()->id;
$employeecode = Auth::user()->employee_code;
if ($id == 'all') {
$data = User::where('hr_status', 0)->where('company_id', $userCompany)->orderBy('last_login_at', 'desc')->get();
}
elseif ($id == "") {
$data = User::where('hr_status', 0)->where('company_id', $userCompany)->where('active', 0)->orderBy('last_login_at', 'desc')->get();
}
elseif ($id == "logged_in") {
$data = User::where('last_login_at', '>', today()->subDays(30))
->where('hr_status', 0)
->where('company_id', $userCompany)
->orderBy('last_login_at', 'desc')
->get();
}
elseif ($id == "not_logged_in") {
$data = User::where('last_login_at', '<', today()->subDays(30))
->orWhereNull('last_login_at')
->where('hr_status', 0)
->where('company_id', $userCompany)
->orderBy('last_login_at', 'desc')
->get();
}
$chart_settings = [
'chart_title' => 'Users By Months',
'chart_type' => 'line',
'report_type' => 'group_by_date',
'model' => 'App\\User',
'group_by_field' => 'last_login_at',
'group_by_period' => 'month',
'aggregate_function' => 'count',
'filter_field' => 'last_login_at',
'column_class' => 'col-md-12',
'entries_number' => '5',
];
$chart = new LaravelChart($chart_settings);
return view('report.report_user_login_logs.user_logs', compact( 'chart'))
->with('employees', $data)
->with('filters', $this->filters)
->with('selectedFilter', $id);
}
view blade:
view/report/report_user_login_logs/index.blade.php
<div class="form-group">
<select class="form-control" id="filter">
<option value="select">Select Search Criteria</option>
#foreach($filters as $filter)
<option value="{{$filter}}" #if($filter==$selectedFilter) selected #endif>{{ucfirst(trans($filter))}}</option>
#endforeach
</select>
</div>
<tbody>
#foreach($employees as $key => $employee)
<tr>
<td>
{{$employee->employee_code}}
</td>
<td>
{{$employee->first_name}} {{$employee->last_name}}
</td>
<td>
{{$employee->email}}
</td>
<td>
{{$employee->last_login_at}}
</td>
</tr>
#endforeach
</tbody>
<script type="text/javascript">
$(document).ready(function () {
$("#filter").change(function(e){
if ($(this).val()=== "select" ){
var url = "{{route('report.report_user_login_logs.user_logs')}}/"
}
else{
var url = "{{route('report.report_user_login_logs.user_logs')}}/" + $(this).val();
}
if (url) {
window.location = url;
}
return false;
});
});
</script>
route/web.php
Route::group(['prefix' => 'report', 'as' => 'report.', 'namespace' => 'Report', 'middleware' => ['auth']], function () {
Route::get('report_user_login_logs/user_logs/{id?}', 'ReportUserLoginLogsController#user_logs')->name('report_user_login_logs.user_logs');
});
I use the dropdown as filter to display the data on the table. The doropdown onchange:
<select class="form-control" id="filter">
<option value="select">Select Search Criteria</option>
#foreach($filters as $filter)
<option value="{{$filter}}" #if($filter==$selectedFilter) selected #endif>{{ucfirst(trans($filter))}}</option>
#endforeach
</select>
When I select "All", it works.
But when I select
"logged in users" as in "logged_in" => "logged in users",
or
"not logged in users" "not_logged_in" => "not logged in users",
I got this error:
production.ERROR: Undefined variable: data
How do I resolve it?
Thank you
I have a controller that shows modules for my each position
Array
(
[0] => Array
(
[layout_module_id] => 1
[layout_id] => 1
[module_id] => 1
[position] => column_left
[sort_order] => 1
)
[1] => Array
(
[layout_module_id] => 2
[layout_id] => 1
[module_id] => 2
[position] => column_left
[sort_order] => 2
)
)
Above currently I have only two modules set and the are in the position of column left.
Because the position views are out side of the foreach loop they are picking up that module even though not set for that position? As shown in image.
Question: How can I make sure that the module will only display in its set position view.
public function index() {
$layout_id = $this->getlayoutID($this->router->class);
$modules = $this->getlayoutsmodule($layout_id);
echo '<pre>';
print_r($modules);
echo "</pre>";
$data['modules'] = array();
foreach ($modules as $module) {
$this->load->library('module/question_help');
$data['modules'][] = $this->load->view('module/question_help', $this->question_help->set(), TRUE);
}
// Position Views
$data['column_left'] = $this->load->view('column_left', $data, TRUE);
$data['column_right'] = $this->load->view('column_right', $data, TRUE);
$data['content_top'] = $this->load->view('content_top', $data, TRUE);
$data['content_bottom'] = $this->load->view('content_bottom', $data, TRUE);
// Main view
$this->load->view('welcome_message', $data);
}
public function getlayoutsmodule($layout_id) {
$this->db->select('*');
$this->db->from('layouts_module');
$this->db->where('layout_id', $layout_id);
$query = $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
}
}
Each of the position views have the same foreach loop
<?php if ($modules) { ?>
<?php foreach ($modules as $module) { ?>
<?php echo $module;?>
<?php } ?>
<?php }?>
main view
<div class="container">
<div class="row">
<?php echo $column_left; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
<div id="content" class="<?php echo $class; ?>">
<?php echo $content_top; ?>
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/Welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide.</p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds. <?php echo (ENVIRONMENT === 'development') ? 'CodeIgniter Version <strong>' . CI_VERSION . '</strong>' : '' ?></p>
<?php echo $content_bottom; ?>
</div>
<?php echo $column_right; ?></div>
</div>
Got it working I have had to use a foreach switch statement
<?php
class Welcome extends CI_Controller {
public function index() {
$layout_id = $this->getlayoutID($this->router->class);
$column_left = '';
$column_right = '';
$content_top = '';
$content_bottom = '';
$position = array('column_left', 'column_right', 'content_top', 'content_bottom');
foreach ($position as $key) {
switch ($key) {
case 'column_left':
$data['modules'] = array();
$layout_module_results = $this->getlayoutsmodule($layout_id, 'column_left');
if (!empty($layout_module_results)) {
foreach ($layout_module_results as $layout_module_result) {
$data['modules'][] = array(
'position' => $layout_module_result['position']
);
}
}
$column_left = $this->load->view('column_left', $data, TRUE);
break;
case 'column_right':
$data['modules'] = array();
$layout_module_results = $this->getlayoutsmodule($layout_id, 'column_right');
if (!empty($layout_module_results)) {
foreach ($layout_module_results as $layout_module_result) {
$data['modules'][] = array(
'position' => $layout_module_result['position']
);
}
}
$column_right = $this->load->view('column_right', $data, TRUE);
break;
case 'content_top':
$data['modules'] = array();
$layout_module_results = $this->getlayoutsmodule($layout_id, 'content_top');
if (!empty($layout_module_results)) {
foreach ($layout_module_results as $layout_module_result) {
$data['modules'][] = array(
'position' => $layout_module_result['position']
);
}
}
$content_top = $this->load->view('content_top', $data, TRUE);
break;
case 'content_bottom':
$data['modules'] = array();
$layout_module_results = $this->getlayoutsmodule($layout_id, 'content_bottom');
if (!empty($layout_module_results)) {
foreach ($layout_module_results as $layout_module_result) {
$data['modules'][] = array(
'position' => $layout_module_result['position']
);
}
}
$content_bottom = $this->load->view('content_bottom', $data, TRUE);
break;
}
}
$data['column_left'] = $column_left;
$data['column_right'] = $column_right;
$data['content_top'] = $content_top;
$data['content_bottom'] = $content_bottom;
$this->load->view('welcome_message', $data);
}
}
how to form popup model validation in codeigniter without using javascript and jquery
public function login() {
$email = $this->input->post('email');
$password = $this->input->post('password');
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'password', 'trim|required|min_length[4]|max_length[40]');
if ($this->form_validation->run() && $this->Login_model->loginn($email, $password)) {
$this->welcome();
} else {
$this->form_validation->set_message('check_database', 'Invalid username or password');
$this->index();
}
}
view page, how to form popup model validation in codeigniter without using javascript and jquery
<form id="register-form" onsubmit ="return validateForm()" action="<?php echo base_url(); ?>Index.php/Login_cntrl/login" method="POST" >
<div class="field-wrap">
<label class="view-label">Email Address</label>
<input type="email" placeholder="Email Address" name="email" id="email" class="input-control" value=""/>
</div>
<div class="field-wrap">
<input type="password" placeholder="Password" name="password" id="password" value="" />
<a href="javascript:void(0)" class="btn btn-link btn-nobg" id="btn-show-forgot" >Forgot ?</a>
</div>
<div class="field-wrap">
<button type="submit" class="btn btn-submit" name="ulogin" id="ulogin" value="ulogin" >Login</button>
</div>
<div class="field-wrap">
NEW User? Sign up
</div>
</form>
model code,how to form popup model validation in codeigniter without using javascript and jquery
public function loginn($email, $password) {
// $this->db->where('email', $email);
$where="(email='$email' or mobile_no='$email') and password='$password'";
$this->db->where($where);
$query = $this->db->get('customer_registration');
$count = $query->num_rows(); //counting result from query
if ($count === 0) {
// $this->db->where('email', $email);
$where="(email='$email' or mobile_no='$email') and password='$password'";
$this->db->where($where);
// $this->db->where('password', $password);
$query = $this->db->get('supplier_registration');
}
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
//add all data to session
$newdata = array(
'id' => $row->id,
'first_name' => $row->first_name,
'last_name' => $row->last_name,
'email' => $row->email,
'password' => $row->password,
'mobile_number' => $row->mobile_number,
'logged_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
return true;
}
return false;
}
Below shown code is working properly
public function loginn($email, $password) {
// $this->db->where('email', $email);
$where = "(email='$email' or mobile_no='$email') and password='$password'";
$this->db->where($where);
$query = $this->db->get('customer_registration');
$count = $query->num_rows(); //counting result from query
$tablename = "customer";
if ($count === 0) {
// $this->db->where('email', $email);
$where = "(email='$email' or mobile_no='$email') and password='$password'";
$this->db->where($where);
// $this->db->where('password', $password);
$query = $this->db->get('supplier_registration');
$tablename = "supplier";
}
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
//add all data to session
$newdata = array(
'id' => $row->id,
'first_name' => $row->first_name,
'last_name' => $row->last_name,
'email' => $row->email,
'password' => $row->password,
'mobile_number' => $row->mobile_number,
'log_in' => TRUE,
);
}
$this->session->set_userdata($newdata);
return $tablename;
}
return $tablenam = " '";
}
here i have given validation for multiple select and even if i choose value from select field and gave submit then also its telling to select the field and am using codeigniter 3.0.6. searched alot but couldn't find the solution;
Here is my controller
function online_booking() {
$this->form_validation->set_rules('course', 'Course', 'required');
$this->form_validation->set_rules('branch', 'Branch', 'required');
if($crs = $this->input->post('course'))
{
$course = implode(',',$crs);
var_dump($course);
}
if ($this->form_validation->run() == TRUE)
{
$this->load->model('branch_model');
$data = array('course' => $course, 'branch' => $this->input->post('branch'));
$id = $this->branch_model->insert_enquiry($data);
if ($id)
{
$this->session->set_flashdata('message', 'Booking has been Succeed,We will contact you shortly.');
redirect('online-booking');
}
else
{
$this->session->set_flashdata('message', 'Error has been occured,try again.');
redirect('online-booking');
}
}
$data['active'] = 'online';
$data['program'] = $this->home_model->get_program();
$this->load->view('online_bookin', $data);
}
here is my view page
<div class="form-group col-md-6">
<label for="exampleInputEmail1">Course to be opted*</label>
<select class="form-control" name="course[]" id="course" multiple="multiple">
<option value="">Select Course</option>
<?php foreach ($program->result() as $row) if($row->parent_id !=0) {?>
<option value="<?php echo $row->id; ?>" <?php echo set_select('course',$row->id) ?> ><?php echo $row->name; ?></option>
<?php } ?>
</select>
</div>
this is my callback function
function is_multiple_select() {
$crs=$this->input->post('course');
if(!$crs)
{
$this->form_validation->set_message('is_multiple_select','You did not select any course to upload.');
return false;
}
else
{
return true;
}
}
this is my model
public function insert_enquiry($data=array())
{
if($this->db->insert(`enquiryform`,$data))
{
return $this->db->insert_id();
}
else
{
return false;
}
}
Why are you using this code:
if($crs = $this->input->post('course'))
{
$course = implode(',',$crs);
var_dump($course);
}
Remove it and check if it works. Or place it inside the $this->form_validation->run() == TRUE block.
function is_multiple_select() {
$crs=$this->input->post('course');
if(!empty($crs) && count($crs)>0)
{
return true;
}
else
{
$this->form_validation->set_message('is_multiple_select','You did not select any course to upload.');
return false;
}
}
//Changes
if ($this->form_validation->run() == TRUE)
{
//You can't save an array directly.
$data = array('course' => implode(",",$this->input->post('course') ), 'branch' => $this->input->post('branch') );
$this->db->insert(`enquiryform`,$data);
$insert_id = $this->db->insert_id();
}
while retrieving explode the course it.
I am trying to update some calendar data to database. But each time I update it updates my day column it updates with 18<span class="label label-danger" xss=removed>Notice</span> It should only update day column with number 18
I am not sure why the $this->input->post('day') has added the span information.
Here is my var dump.
array (size=2)
17 => string 'Event 17-12-15' (length=14)
'18<span class="label label-danger" xss=removed>Notice</span>' => string '26' (length=2)
Quesions:
How is it possible to only update day column with number and not with span?
What could be causing it to have span updated with number?
Tried:
$this->input->post('day', TRUE)
$this->input->post('day', FALSE)
Controller
Note: I am using models functions on controller just for testing
<?php
class Calendar extends MX_Controller {
public function __construct() {
parent::__construct();
$this->load->model('dashboard/model_calendar');
$this->load->library('calendar');
}
public function index() {
if ($this->uri->segment(3) == FALSE) {
$year = date('Y');
} else {
$year = $this->uri->segment(3);
}
$data['year'] = $year;
if ($this->uri->segment(4) == FALSE) {
$month = date('m');
} else {
$month = $this->uri->segment(4);
}
$data['month'] = $month;
var_dump($this->get_calendar_data($year, $month));
$prefs = array(
'start_day' => 'monday',
'show_next_prev' => true,
'day_type' => 'long',
'next_prev_url' => base_url('dashboard/calendar')
);
$prefs['template'] = '
{table_open}<table border="0" cellpadding="0" cellspacing="0" class="table table-striped table-bordered calendar">{/table_open}
{heading_row_start}<tr>{/heading_row_start}
{heading_previous_cell}<th><i class="fa fa-chevron-left fa-2x "></i></th>{/heading_previous_cell}
{heading_title_cell}<th class="text-center" colspan="{colspan}">{heading}</th>{/heading_title_cell}
{heading_next_cell}<th class="text-right"><i class="fa fa-chevron-right fa-2x"></i></th>{/heading_next_cell}
{heading_row_end}</tr>{/heading_row_end}
{week_row_start}<tr>{/week_row_start}
{week_day_cell}<td>{week_day}</td>{/week_day_cell}
{week_row_end}</tr>{/week_row_end}
{cal_row_start}<tr class="days">{/cal_row_start}
{cal_cell_start}<td class="day">{/cal_cell_start}
{cal_cell_content}
<div class="day_num">{day}<span class="label label-danger" style="margin-left: 10px;">Notice</span></div>
<div class="content">{content}</div>
{/cal_cell_content}
{cal_cell_content_today}
<div class="day_num highlight">{day}</div>
<div class="content">{content}</div>
{/cal_cell_content_today}
{cal_cell_no_content}<div class="day_num">{day}</div>{/cal_cell_no_content}
{cal_cell_no_content_today}<div class="day_num highlight">{day} <span class="label label-success">Current Day</span></div>{/cal_cell_no_content_today}
{cal_cell_blank} {/cal_cell_blank}
{cal_cell_end}</td>{/cal_cell_end}
{cal_row_end}</tr>{/cal_row_end}
{table_close}</table>{/table_close}
';
$this->calendar->initialize($prefs);
if ($this->input->post('day')) {
$this->update_calendar_event($year, $month);
}
$data = $this->get_calendar_data($year, $month);
$data['calendar'] = $this->calendar->generate($year, $month, $data);
$this->load->view('dashboard/calender_view', $data);
}
public function update_calendar_event($year, $month) {
$date = $year .'-'. $month .'-'. $this->input->post('day');
$calendar = array(
'year' => $year,
'month' => $month,
'day' => $this->input->post('day', TRUE),
'data' => $this->input->post('data')
);
$this->db->where('date', $date);
$this->db->update('calendar', $calendar);
}
public function get_calendar_data($year, $month) {
$cell_data = array();
$this->db->select('*');
$this->db->from('calendar');
$this->db->where('year', $year);
$this->db->where('month', $month);
$query = $this->db->get();
foreach ($query->result() as $result) {
$cell_data[$result->day] = $result->data;
}
return $cell_data;
}
public function check_calendar_event($year, $month, $day) {
$date = $year .'-'. $month .'-'. $day;
$this->db->select('year, month, day');
$this->db->from('calendar');
$this->db->where('date', $date);
$results = $this->db->count_all_results();
return $results;
}
}
View
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Calendar</h1>
</div>
<div class="panel-body">
<?php echo $calendar;?>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('.calendar .day').click(function() {
day_num = $(this).find('.day_num').html();
day_data = prompt('Enter Event', $(this).find('.content').html());
if (day_data != null) {
$.ajax({
url: window.location,
type: 'POST',
data: {
day: day_num,
data: day_data
},
success: function(msg) {
location.reload();
}
});
}
});
});
</script>
There could be couple of options why you are having this problem. to find out which one start by checking the does day_num passing to your Controller? do this:
<script type="text/javascript">
$(document).ready(function() {
$('.calendar .day').click(function() {
day_num = $(this).find('.day_num').html();
day_data = prompt('Enter Event', $(this).find('.content').html());
if (day_data != null) {
$.ajax({
url: window.location,
type: 'POST',
data: {
day: day_num,
data: day_data
},
success: function(msg) {
//location.reload(); turn off the reload for now.
alert(day_num); //what does this alert show?
}
});
}
});
});
And leave a comment on what does the alert show you? the number 18 or the whole HTML so i know how to help you..