doucha7329 2015-11-14 13:03
浏览 56
已采纳

单击按钮后将php td值插入textarea

I have echo PHP table with 3 tds: 1- checkbox. 2- names. 3- phone Numbers

I made textarea to contain all checked checkboxes tds phone Numbers into it.

I tried to modificate this code but it doesn't work with me.

My code :

<table class="table table-striped table-bordered TableStyle" id="table-scroll ">
    <thead>
        <th class="thead"><input type="checkbox" name="checkallnum" value="" id="checkallnum2" /></th>
        <th class="thead">Name</th>
        <th class="thead">Phone</th>
    </thead>
    <tbody>
        <tr>
             <td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
             <td>AMMAR</td>
             <td>123456789</td>
        </tr>
         <tr>
             <td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
             <td>Sara</td>
             <td>987654321</td>
        </tr>
    </tbody>
 </table>

<button type="button" id="confirmNums" class="btn btn-primary pull-left" style="">Add</button>

<textarea rows="8" name="" id="sendToNum" class="form-control" style="margin-bottom: 10px;" tabindex="1"></textarea>
  • 写回答

1条回答 默认 最新

  • donjd86266 2015-11-14 13:50
    关注

    A possible solution is to use jQuery.

    Maybe this example can get you started. When you click the 'Add' button, the phonenumbers will be added to the textarea.

    $(document).ready(function() {
      $('#confirmNums').click(function() {
        var newline = "
    ";
        var sendToNum = $('#sendToNum');
        sendToNum.text('');
        $("input[name=check]:checked").each(function() {
          var phoneNumber = $(this).parent().nextAll('td').eq(1).html();
          sendToNum.append(phoneNumber + newline);
        });
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table class="table table-striped table-bordered TableStyle" id="table-scroll ">
        <thead>
        <th class="thead"><input type="checkbox" name="checkallnum" value="" id="checkallnum2" /></th>
        <th class="thead">Name</th>
        <th class="thead">Phone</th>
        </thead>
        <tbody>
        <tr>
            <td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
            <td>AMMAR</td>
            <td>123456789</td>
        </tr>
        <tr>
            <td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
            <td>Sara</td>
            <td>987654321</td>
        </tr>
        </tbody>
    </table>
    
    <button type="button" id="confirmNums" class="btn btn-primary pull-left" style="">Add</button>
    
    <textarea rows="8" name="" id="sendToNum" class="form-control" style="margin-bottom: 10px;" tabindex="1"></textarea>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥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,如何解決?