dongsheng9203 2017-06-05 14:13
浏览 30
已采纳

将已检查的表行添加到电子邮件正文

I have a table where each row can be selected by checking a checkbox. Whatever rows are selected, I am wanting those rows to be pasted to the body of an email that pops up when the "Checkout" button is pressed.

Currently, whenever I hit the "Checkout" button, the email pops up and it will display the first row in the table, whether selected or not, but nothing more.

How can I get multiple selections displayed based on if it is checked?

Table:

<section id="checkout-btn"> 
<button id="checkout" name="order" onclick="sendMail(); return false">Checkout</button>
</section>

<br>

<table id="merchTable" cellspacing="5" class="sortable">
    <thead>
        <tr class="ui-widget-header">
            <th class="sorttable_nosort"></th>
            <th class="sorttable_nosort">Loc</th>
            <th class="merchRow">Report Code</th>
            <th class="merchRow">SKU</th>
            <th class="merchRow">Special ID</th>
            <th class="merchRow">Description</th>
            <th class="merchRow">Quantity</th>
            <th class="sorttable_nosort">Unit</th>
            <th style="display: none;" class="num">Quantity #</th>
        </tr>
    </thead>
    <tbody>

        <?php foreach ($dbh->query($query) as $row) {?>

        <tr>
            <td class="ui-widget-content"><input type="checkbox" class="check" name="check" id="checkid-<?php echo intval ($row['ID'])?>"></td>
            <td class="loc ui-widget-content" data-loc="<?php echo $row['Loc'] ?>"><input type="hidden"><?php echo $row['Loc'];?></td>
            <td name="rows[0][0][rp-code]" class="rp-code ui-widget-content" align="center" data-rp-code="<?php echo $row['Rp-Code'] ?>" id="rp-code-<?php echo intval ($row['Rp-Code'])?>"><?php echo $row['Rp-Code'];?></td>
            <td name="rows[0][0][sku]" class="sku ui-widget-content" data-sku="<?php echo $row['SKU'] ?>" id="sku-<?php echo intval ($row['SKU'])?>"><?php echo $row['SKU'];?></td>
            <td name="rows[0][0][special-id]" class="special-id ui-widget-content" data-special-id="<?php echo $row['Special-ID'] ?>" align="center" id="special-id-<?php echo intval ($row['Special-ID'])?>"><?php echo $row['Special-ID'];?></td>
            <td name="rows[0][0][description]" class="description ui-widget-content" data-description="<?php echo $row['Description'] ?>" id="description-<?php echo intval ($row['Description'])?>"><?php echo $row['Description'];?></td>
            <td name="rows[0][0][quantity]" class="quantity ui-widget-content" data-quantity="<?php echo $row['Quantity'] ?>" align="center" id="quantity-<?php echo intval ($row['Quantity'])?>"><?php echo $row['Quantity'];?></td>
            <td name="rows[0][0][unit]" class="unit ui-widget-content" data-unit="<?php echo $row['Unit'] ?>" id="unit-<?php echo intval ($row['Unit'])?>"><?php echo $row['Unit'];?></td>
            <td name="rows[0][0][quant]" style="display: none;" class="quantity_num ui-widget-content"><input type="textbox" style="width: 100px;" class="spinner" id="spin-<?php echo intval ($row['ID'])?>"></td>
        </tr>

    <?php } ?>

    </tbody>
</table>

Javascript that adds data to email:

function sendMail() {
    var link = "mailto:me@example.com"
             + "?subject=" + encodeURIComponent("Order")
             + "&body=" + encodeURIComponent($('.loc').data('loc')) + '\xa0\xa0' + encodeURIComponent($('.rp-code').data('rp-code')) + '\xa0\xa0' + encodeURIComponent($('.sku').data('sku')) + '\xa0\xa0' + encodeURIComponent($('.special-id').data('special-id')) + '\xa0\xa0' + encodeURIComponent($('.description').data('description')) + '\xa0\xa0' + encodeURIComponent($('.quantity').data('quantity')) + '\xa0\xa0' + encodeURIComponent($('.unit').data('unit')) + '\xa0\xa0' + encodeURIComponent($('.quantity_num').data('quantity_num'));

    window.location.href = link;
}
  • 写回答

2条回答 默认 最新

  • dongyi1441 2017-06-05 15:42
    关注

    While this is terrbile idea to send emails via JS like this, You can try:

    function sendMail(){
      var link = "mailto:me@example.com"
      + "?subject=" + encodeURIComponent("Order")
      + "&body=";
    
      var body = '';
    
      $('table tr input[name="check"]:checked').each(function(){
        var current_tr = $(this).parent().parent();
    
        var loc = current_tr.find('.loc').data('loc');
        body +=  encodeURIComponent(loc) + '\xa0\xa0';
    
        var loc =current_tr.find('.rp-code').data('rp-code');
        body +=  encodeURIComponent(loc) + '\xa0\xa0';
    
      });
    
      body += '"';
      link += body;
      console.log(link);
    }
    

    You need to iterate over every TR that contains checkbox and check if it's :checked . Then add avery data that You need into your's body var.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题