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()
            );
    
        });
    }
    
    已采纳该答案
    打赏 评论
  • dongyongkui6329 2013-04-23 10:27

    You can use hidden fields. On each row add a hidden field, witch will contain the "real value".

    Then add a click/change/whatever event you want to the checkbox, and if user can type the codes a keyup to the input field. The event should send the ending of the "lines" of the ids (like _2, _2, etc. -> in the way you named them).

    All events should call the same function, witch will concat the values into the hidden field.

    Something like this - is an example copy paste won't work ;) :

         function makeName(line) {
             // Loop through checkboxes on that line and make the name
             if (<checkbox is checked>)
                  document.getElementById('hiddenField' + line).value = document.getElementById('product' + line).value + <checkboxFromLoop> // Etc., etc.
         }
    

    On submit just send only the hidden fields. They will contain the correct values.

    打赏 评论

相关推荐 更多相似问题