drgmszo076956 2013-11-25 19:03
浏览 137

按钮单击更新数据库[关闭]

I have been struggling with this for a few days. I have a webpage that has a table of dynamically created data on it (using php and datatable). Everything works great. Now I have 2 columns with buttons for each row :

NAME | ADDRESS   | STAGE | ASSIGN  
John   9 Doe Way   btnS     btnA

All I want to do is when the user clicks the btnS or btnA run a simple update query and put that person that is clicked into the stage or assign category for this activity. (I can handle that part in the database). I can do this fine if I have a hyperlink instead of buttons. I want the page to refresh, because the will remove the name from my list.

So how do I get the ID of the row of the dynamically created button? I have a hidden field for ID if needed.

I would paste code, but I have no idea the correct direction. I have tried jquery (function), form POST function, but nothing seems to work?

Thanks!!

  • 写回答

4条回答 默认 最新

  • dqjl0906 2013-11-25 19:11
    关注

    You can insert an onclick attribute to your button like this:

    <button onclick="location.href='http://www.example.com/yourscript.php?id='+ parentNode.parentNode.childNodes[0].innerHTML" />Delete</button>
    

    There's another solution also:

    <form action="">
      <input type="submit" name="SaveChanges" value="Delete" onclick="this.form.action='http://www.example.com/yourscript.php?id='+ parentNode.parentNode.childNodes[0].innerHTML;" />
    </form>
    

    So..

    <table>
      <tr><th>ID</th><th>Address</th><th>Delete</th></tr>
      <tr><td id="id">1</td>
          <td>John</td>
          <td>9 Doe Way</td>
          <td><button onclick="location.href='http://www.example.com/yourscript.php?id='+ parentNode.parentNode.childNodes[0].innerHTML" />Delete</button></td></tr>
    </table>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容