update html table td without refreshing | Newbie | | Join Date: Oct 2009
Posts: 3
| |
Hi all,i'm trying to show updated data in existing html td.. For example i got column that show last modified datetime,then i want to update data again,the column will changed to current time without refreshing the page.These are my codes
views/order_home -
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.js"></script>
-
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.form.js"></script>
-
<script type="text/javascript">
-
// wait for the DOM to be loaded
-
$(document).ready(function()
-
{ $("#msg").hide();
-
$('#myform').ajaxForm(function()
-
{
-
var id = $('#id').val();
-
$.post("order/getOrder/", { 'id' : id },
-
function(data){
-
$('#modif').html(data.modified);
-
}, "json");
-
$("#msg").html("Berhasil update order").fadeIn(1500);
-
$("#msg").fadeOut(1500);
-
});
-
});
-
</script> <h1><?php echo $title;?></h1>
-
<?php
-
if ($this->session->flashdata('message')){
-
echo "<div class='message' name='msg' id='msg'>".$this->session->flashdata('message')."</div>";
-
}
-
echo "<div name='msg' class ='msg' id='msg'></div>";
-
//echo "<div class='message' name='msg' id='msg'></div>";
-
-
echo "<table border='1' cellspacing='0' cellpadding='3' width='100%' id='order_home' name='order_home'>\n";
-
echo "<tr valign='top'>\n";
-
echo "<th>No Order</th>\n<th>No Cust</th><th>Tgl Pesan</th><th>Modified</th><th>Status</th><th>Update</th><th>Actions</th>\n";
-
echo "</tr>\n";
-
if (count($order)){
-
foreach ($order as $key => $list){
-
echo "<tr valign='top'>\n";
-
echo "<td>".anchor("admin/order/detail/".$list['no_order'],$list['no_order'])."</td>\n";
-
echo "<td>".$list['custid']."</td>\n";
-
$datetime = strtotime($list['tgl_pesan']);
-
$orderdate = date("d-m-y H:i ", $datetime);
-
echo "<td>".$orderdate."</td>\n";
-
$modifieddate = strtotime($list['modified']);
-
$modified = date("d-m-y H:i:s ", $modifieddate);
-
echo "<td id='modif' name='modif'>".$modified."</td>\n";
-
$attributes = array('id' => 'myform');
-
echo form_open('admin/order/edit',$attributes);
-
echo "<td align='center'>".form_dropdown('status',$status,$list['status'])."</td>\n";
-
echo '<input type="hidden" id="id" name="id" value="'.$list['id'].'" />';
-
$data = array('name'=>'notif','id'=>'notif');
-
echo "<td align='center'>".form_checkbox($data)."<label for='update'>Notifikasi cust</label>".form_submit('submit','Update')."</td>\n";
-
echo "<td align='center'>";
-
echo anchor("admin/order/edit/".$list['no_order'],img(base_url().'/images/edit.jpg'));
-
echo " | ";
-
echo anchor("admin/order/delete/".$list['no_order'],img(base_url().'/images/delete.jpg'));
-
echo "</td>\n";
-
echo "</tr>\n";
-
echo form_close();
-
}
-
}
-
echo "</table>";
-
?>
-
controller/order -
function edit($no=0)
-
{
-
if ($this->input->post('id'))
-
{
-
if (isset($_REQUEST['notif']))
-
{
-
$this->input->post('status_order');
-
$result=$this->MOrder->updateOrder();
-
$this->email->from('admin@7com.cphoster.com','Admin');
-
$this->email->to('yonghan79@gmail.com');
-
$this->email->subject('Testing email class');
-
$this->email->message('Status order '.$status);
-
$this->email->send();
-
$this->session->set_flashdata('message','Berhasil update order');
-
redirect('admin/order/index','refresh');
-
}
-
else
-
{
-
$this->MOrder->updateOrder();
-
$this->session->set_flashdata('message','Berhasil update order');
-
redirect('admin/order/index','refresh');
-
}
-
}
-
}
-
-
function getOrder()
-
{
-
$no = $this->input->post('id');
-
$hasil=$this->MOrder->getOrder($no);
-
$array=array('modified'=>$hasil['modified']);
-
echo json_encode($array);
-
-
}
-
this is my testing site testing site
username : admin
password : admin
The issue is in the order page...Thanks a lot
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: update html table td without refreshing
Line 12 seems to be where you're setting the time. What's the value of data.modified?
| | Newbie | | Join Date: Oct 2009
Posts: 3
| | | re: update html table td without refreshing
It's datetime acoder... -
# $modifieddate = strtotime($list['modified']);
-
# $modified = date("d-m-y H:i:s ", $modifieddate);
-
# echo "<td id='modif' name='modif'>".$modified."</td>\n";
-
If i update the first row,it works fine.But if i update the second row,the td doesn'r show the way it should be..Thanks...
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: update html table td without refreshing
Ah right, so it's just a formatting problem. What you can do is either use the Date object methods (get***) or split the modified (string) value to get the date/time separately, i.e. on the space character - see split(). Then split on the hyphen to get the date parts and swap them around.
If you want to avoid all that, try using some code like this.
| | Newbie | | Join Date: Oct 2009
Posts: 3
| | | re: update html table td without refreshing
Actually it's not a formatting problem acoder. ^_^ Praise God i got it working already..I should loop the form.. ^_^ Thanks for your help acoder.God bless you.. ^_^
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: update html table td without refreshing
You had the same ID multiple times which is not allowed. IDs must be unique, so the wrong element was being selected.
|  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,414 network members.
|