942,782 Members | Top Members by Rank

Ad:
Oct 31st, 2009
0

change html table td value without refreshing

Expand Post »
Hi all,suppose i got two rows like this picture

http://i575.photobucket.com/albums/s...an79/ask-1.jpg

I'm trying to change the modified column value to current datetime without refreshing the page when i click the update button..The first row worked,the second doesn't work..Here is my codes

views/order_home
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  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.  
  4. <script type="text/javascript">
  5. // wait for the DOM to be loaded
  6. $(document).ready(function()
  7. {
  8. $("#msg").hide();
  9. $('#myform').ajaxForm(function()
  10. {
  11. var no_id=$('#no_id').val();
  12.  
  13. $.post("getOrder/", { 'id' : no_id },
  14. function(data){
  15. $('#modif').html(data.modified);
  16. }, "json");
  17.  
  18. //nampilin di div message string yg ada di dalam html()
  19. $("#msg").html("Berhasil update order").fadeIn(1500);
  20. $("#msg").fadeOut(1500);
  21. });
  22. });
  23. </script> <h1><?php echo $title;?></h1>
  24. <?php
  25. if ($this->session->flashdata('message')){
  26. echo "<div class='message' name='msg' id='msg'>".$this->session->flashdata('message')."</div>";
  27. }
  28. echo "<div name='msg' class ='msg' id='msg'></div>";
  29.  
  30. echo "<table border='1' cellspacing='0' cellpadding='3' width='100%' id='order_home' name='order_home'>\n";
  31. echo "<tr valign='top'>\n";
  32. echo "<th>No Order</th>\n<th>No Cust</th><th>Tgl Pesan</th><th>Modified</th><th>Status</th><th>Update</th><th>id</th><th>Actions</th>\n";
  33. echo "</tr>\n";
  34. if (count($order)){
  35. foreach ($order as $key => $list){
  36. echo "<tr valign='top'>\n";
  37. echo "<td>".anchor("admin/order/detail/".$list['no_order'],$list['no_order'])."</td>\n";
  38. echo "<td>".$list['custid']."</td>\n";
  39. $datetime = strtotime($list['tgl_pesan']);
  40. $orderdate = date("d-m-y H:i ", $datetime);
  41. echo "<td>".$orderdate."</td>\n";
  42. $modifieddate = strtotime($list['modified']);
  43. $modified = date("d-m-y H:i ", $modifieddate);
  44. echo "<td id='modif' name='modif'>".$modified."</td>\n";
  45. $attributes = array('id' => 'myform');
  46. echo form_open('admin/order/edit',$attributes);
  47. echo "<td align='center'>".form_dropdown('status',$status,$list['status'])."</td>\n";
  48. $btn = array('id'=>'update','name'=>'update','value'=>'Update');
  49. $data = array('name'=>'notif','id'=>'notif');
  50. echo "<td align='center'>".form_checkbox($data)."<label for='update'>Notifikasi cust</label>".form_submit($btn)."</td>\n";
  51. echo '<input type="hidden" id="no_id" name="no_id" value="'.$list['id'].'" />';
  52. echo form_close();
  53. echo "<td align='center'>";
  54. echo anchor("admin/order/edit/".$list['no_order'],img(base_url().'/images/edit.jpg'));
  55. echo " | ";
  56. echo anchor("admin/order/delete/".$list['no_order'],img(base_url().'/images/delete.jpg'));
  57. echo "</td>\n";
  58. echo "</tr>\n";
  59. }
  60. }
  61. echo "</table>";
  62. ?>

controller/order
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function edit($no=0)
  2. {
  3. if ($this->input->post('no_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. //return $result;
  15. $this->session->set_flashdata('message','Berhasil update order');
  16. redirect('admin/order/index','refresh');
  17. }
  18. else
  19. {
  20. $this->MOrder->updateOrder();
  21. $this->session->set_flashdata('message','Berhasil update order');
  22. redirect('admin/order/index','refresh');
  23. }
  24. }
  25. else
  26. {
  27. //$id = $this->uri->segment(4);
  28. $data['title'] = "Edit Order";
  29. $data['main'] = 'admin/order_edit';
  30. $data['order'] = $this->MOrder->getOrder($no);
  31. $data['status']=$this->MOrder->getStatus();
  32. if (!count($data['order'])){
  33. redirect('admin/order/index','refresh');
  34. }
  35. $this->load->vars($data);
  36. $this->load->view('dashboard');
  37. }
  38. }
  39.  
  40. //buat ambil data dari db menggunakan jquery n json
  41. function getOrder()
  42. {
  43. $no=trim($this->input->post('id'));
  44. $hasil=$this->MOrder->getOrder($no);
  45. $datetime = strtotime($hasil['modified']);
  46. $orderdate = date("d-m-y H:i ", $datetime);
  47. $array=array('modified'=>$orderdate);
  48. echo json_encode($array);
  49. }

Are there anything wrong with my codes?What should i do?Thanks a lot...
Last edited by yonghan; Oct 31st, 2009 at 7:10 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yonghan is offline Offline
7 posts
since Jul 2008
Oct 31st, 2009
0
Re: change html table td value without refreshing
Yonghan,

In these lines (and maybe others), checkboxes, Update buttons and hidden input fields all get the same id and name on each pass through the foreach loop. It therefore appears that the javascript/jquery code has no way to distinguish one row from another.

php Syntax (Toggle Plain Text)
  1. $btn = array('id'=>'update','name'=>'update','value'=>'Update');
  2. $data = array('name'=>'notif','id'=>'notif');
  3. echo "<td align='center'>".form_checkbox($data)."<label for='update'>Notifikasi cust</label>".form_submit($btn)."</td>\n";
  4. echo '<input type="hidden" id="no_id" name="no_id" value="'.$list['id'].'" />';
Airshow
Sponsor
Reputation Points: 299
Solved Threads: 355
WiFi Lounge Lizard
Airshow is offline Offline
2,513 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: make html element empty
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Preview Pic on page Script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC