Using jquery modal box and ajax to display values from cell table

依然范特西╮ 提交于 2019-12-24 08:15:19

问题


I'm trying to do an UPDATE function by using Jquery modal dialog box to pass the values to the controller. However, I'm displaying my values in a HTML table box, is there a way to pass the values from the table row to the modal box? I want to do it in a way when i click the row, the values will be displayed in the modal. I'm also unsure of how to link a jquery dialog box to a table row.

This is the table

These are the codes for it

<form id="searchtable" >
               <%--List Table--%>
               <table border = 1 cellpadding = 2  cellspacing = 2 id="normal">
              <tr>
                 <th width=9.7%>ID</th>
                 <th width=24%>Username</th>     
                 <th width=13%>Account ID</th>
                 <th width=29%>Email</th>
                 <th width=10%>User ID</th>
                 <th width=12%>Device ID</th>         
              </tr>
         </table>

              <div style="height: 250px; overflow: scroll; width: 100%;">
              <table id="normal">
              <g:each in = "${result}">
              <tr>
              <td width=10%>${it.ID}</td>
              <td width=25%>${it.Username}</td>
              <td width=13.5%>${it.account_id}</td>
              <td width=30.5%>${it.email}</td>
              <td width=10.5%>${it.user_id}</td>
              <td width=13%>${it.device_id }</td>
              </tr>
              </g:each>


              </table>
         </div>        
    </form>

This is an example of the dialog box of how it should appear

Thank you guys so much. If needed, I can provide you guys with the codes.


回答1:


use .btn class to your tr and inclose your username value to

<span class="username">${it.username}</span>

your jquery should

$(document).ready(function() {
  $(".btn tr").live("click", function{
    var name = $(this).find(".username").text();
    ...put your code here that will update your table...
  });
});

if you click the tr, it will find its child with class "username" and will get the data for you.



来源:https://stackoverflow.com/questions/14574205/using-jquery-modal-box-and-ajax-to-display-values-from-cell-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!