dpnhp20440 2013-04-23 10:14
浏览 26
已采纳

Jquery / PHP根据连接的[输入值和列名]在输入中插入值。 jquery 1.9.1或php

I have the below table:

<table class="authors-list" border=0 id="ordertable">
  <tr>
     <td ><input type="text" id="product_1" name="product_1" class="rounded"/></td>
     <td ><input type="text" size='5' id="qty_1" name="qty_1" class="rounded"/></td> 
     <td class="tdcheckbox"><input type="checkbox"  id="h09_1" name="h09_1" class="rounded"/>
      <input type="text"  id="line_1_09" name="line_1_09" value=""></td> 
     <td class="tdcheckbox"><input type="checkbox"  id="h12_1" name="h12_1" class="rounded"/>
      <input type="text"  id="line_1_12" name="line_1_12" value=""></td> 
     <td class="tdcheckbox"><input type="checkbox"  id="h15_1" name="h15_1" class="rounded"/>
      <input type="text"  id="line_1_15" name="line_1_15" value=""></td>
     <td><input type="text" name="cubespercheck_1" id="cubespercheck_1" value="0" size=5></td>
  </tr>
</table>

you can see the fiddle here: http://jsfiddle.net/3Befc/7/

My main goal is to be able to post each checkbox as an individual product. the product field is populated with a product family. example is 38114CR. the checkboxes represent the lengths of the product. the code for a 1.8 meter length of 38114CR is 3811418CR where 18 is the length (1.8)

In the end, I want to be able to post each checked checkbox as its unique product code. so if 0.9 is checked for product 38114CR post the value 3811409CR.

My ultimate goal is to insert the following into a database: (this is as per the fiddles desired result)

**Product           Cubes**

3011409CR           7
3011412CR           7
2011512EX           3
2011515EX           3
5050009PT           2
5050012PT           2
5050015PT           2

The only way I can think of is to loop through the table, and where there is a checked checkbox, combine the name and the length but even that has some challenges.

How can I get the above table rows to insert into a database? so horizontal row to vertical record insert?

Keep in mind that the user can input any product code they want.

  • 写回答

2条回答 默认 最新

  • dongyu4908 2013-04-23 20:44
    关注
    $(function () {
        $('#continue').on('click', function () {
            createcodes();
        });
    });
    
    
    function createcodes() {
    
        //run through each row
        $('.authors-list tr').each(function (i, row) {
    
            // reference all the stuff you need first
            var $row = $(row),
                $line = $row.find('input[name^=line]'),
                $family = $row.find('input[name*="family"]'),
                $size = $row.find('input[name^=size]'),
                $grade = $row.find('input[name*="grade"]');
    
            $line.val(
                $family.val() + ' ' + $size.val() + ', ' + $grade.val()
            );
    
        });
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?