Connecting Tech Pros Worldwide Forums | Help | Site Map

update html table td without refreshing

Newbie
 
Join Date: Oct 2009
Posts: 3
#1: 3 Weeks Ago
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
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.js"></script>
  2. <script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.form.js"></script>
  3. <script type="text/javascript"> 
  4. // wait for the DOM to be loaded 
  5. $(document).ready(function() 
  6. { $("#msg").hide();
  7. $('#myform').ajaxForm(function()
  8. {
  9. var id = $('#id').val();
  10. $.post("order/getOrder/", { 'id' : id },
  11. function(data){
  12. $('#modif').html(data.modified);
  13. }, "json");
  14. $("#msg").html("Berhasil update order").fadeIn(1500);
  15. $("#msg").fadeOut(1500);
  16. });
  17. }); 
  18. </script> <h1><?php echo $title;?></h1>
  19. <?php
  20. if ($this->session->flashdata('message')){
  21. echo "<div class='message' name='msg' id='msg'>".$this->session->flashdata('message')."</div>";
  22. }
  23. echo "<div name='msg' class ='msg' id='msg'></div>";
  24. //echo "<div class='message' name='msg' id='msg'></div>";
  25.  
  26. echo "<table border='1' cellspacing='0' cellpadding='3' width='100%' id='order_home' name='order_home'>\n";
  27. echo "<tr valign='top'>\n";
  28. 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";
  29. echo "</tr>\n";
  30. if (count($order)){
  31. foreach ($order as $key => $list){
  32. echo "<tr valign='top'>\n";
  33. echo "<td>".anchor("admin/order/detail/".$list['no_order'],$list['no_order'])."</td>\n";
  34. echo "<td>".$list['custid']."</td>\n";
  35. $datetime = strtotime($list['tgl_pesan']);
  36. $orderdate = date("d-m-y H:i ", $datetime);
  37. echo "<td>".$orderdate."</td>\n";
  38. $modifieddate = strtotime($list['modified']);
  39. $modified = date("d-m-y H:i:s ", $modifieddate);
  40. echo "<td id='modif' name='modif'>".$modified."</td>\n";
  41. $attributes = array('id' => 'myform');
  42. echo form_open('admin/order/edit',$attributes);
  43. echo "<td align='center'>".form_dropdown('status',$status,$list['status'])."</td>\n";
  44. echo '<input type="hidden" id="id" name="id" value="'.$list['id'].'" />';
  45. $data = array('name'=>'notif','id'=>'notif');
  46. echo "<td align='center'>".form_checkbox($data)."<label for='update'>Notifikasi cust</label>".form_submit('submit','Update')."</td>\n";
  47. echo "<td align='center'>";
  48. echo anchor("admin/order/edit/".$list['no_order'],img(base_url().'/images/edit.jpg'));
  49. echo " | ";
  50. echo anchor("admin/order/delete/".$list['no_order'],img(base_url().'/images/delete.jpg'));
  51. echo "</td>\n";
  52. echo "</tr>\n";
  53. echo form_close();
  54. }
  55. }
  56. echo "</table>";
  57. ?>
  58.  
controller/order
Expand|Select|Wrap|Line Numbers
  1. function edit($no=0)
  2. {
  3. if ($this->input->post('id'))
  4. {
  5. if (isset($_REQUEST['notif']))
  6. {
  7. $this->input->post('status_order');
  8. $result=$this->MOrder->updateOrder();
  9. $this->email->from('admin@7com.cphoster.com','Admin');
  10. $this->email->to('yonghan79@gmail.com');
  11. $this->email->subject('Testing email class');
  12. $this->email->message('Status order '.$status);
  13. $this->email->send();
  14. $this->session->set_flashdata('message','Berhasil update order');
  15. redirect('admin/order/index','refresh');
  16. }
  17. else
  18. {
  19. $this->MOrder->updateOrder();
  20. $this->session->set_flashdata('message','Berhasil update order');
  21. redirect('admin/order/index','refresh');
  22. }
  23. }
  24. }
  25.  
  26. function getOrder()
  27. {
  28. $no = $this->input->post('id');
  29. $hasil=$this->MOrder->getOrder($no);
  30. $array=array('modified'=>$hasil['modified']);
  31. echo json_encode($array);            
  32.  
  33.     }
  34.  
this is my testing site

testing site
username : admin
password : admin

The issue is in the order page...Thanks a lot



acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: 3 Weeks Ago

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
#3: 3 Weeks Ago

re: update html table td without refreshing


It's datetime acoder...
Expand|Select|Wrap|Line Numbers
  1. # $modifieddate = strtotime($list['modified']);
  2. # $modified = date("d-m-y H:i:s ", $modifieddate);
  3. # echo "<td id='modif' name='modif'>".$modified."</td>\n";
  4.  
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...
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: 3 Weeks Ago

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
#5: 3 Weeks Ago

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.. ^_^
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: 2 Weeks Ago

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.
Reply


Similar JavaScript / Ajax / DHTML bytes