Jquery for a circular table, for each row and td concatonate values

I have a table with several rows. Each row has a product field, a rating field, and a family field.

Then for each available size there are several flags.

The row in the table is as follows:

<table class="authors-list" border=0 id="ordertable"> <tr> <td style="font-size:10px;"><a class="deleteRow"> <img src="<?php echo base_url() ?>application/assets/images/delete2.png" /></a></td> <td ><input type="text" id="product1" name="product1" class="rounded"/></td> <td ><input type="text" size='5' id="qty1" name="qty1" 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=""> <input type="text" id="size_1_09" name="size_1_09" value="09"> </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=""> <input type="text" id="size_1_12" name="size_1_12" value="12"> </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=""> <input type="text" id="size_1_15" name="size_1_15" value="15"> </td> <td><input type="text" name="cubespercheck_1" id="cubespercheck_1" value="0" size=5></td> <td><input type="text" name="skufamily_1" id="skufamily_1"></td> <td><input type="text" name="skugrade_1" id="skugrade_1"></td> </tr> </table> <input type="button" id="continue" value="continue"> 

all fields will be hidden in the final result, except for the product field.

To provide you the background, my product code is as follows: 3811460S5 38114 - width and height 60 - length Cr - this is a class.

What I want is that when I click the button, jquery should go through all the cells of the table. where the CHOCKKED flag is set And the product was filled, jquery should join the fields as shown below: skufamily (for row [skufamily]) + length (from cell [size]) + rating (from row [skugrade])

this result should fill in the current td line input. so now each cell will have an exact sku value (only if checked and filled with product)

skufamily, the size and class are pre-populated, so you just need jquery to loop and join the fields.

here is a violin to play on. http://jsfiddle.net/QS56z/

I tried the following concept but couldn't attach the code.

  function createcodes() { $("table.authors-list").find('input[type="checkbox"][name^="h"]:checked').each(function () { if (<checkbox is checked>) document.getElementById(input[type="skufamily").value + document.getElementById(input[type="size").value + document.getElementById(input[type="skugrade").value }); 

This is far from right, so if you can put me on the right path, I would appreciate it.

Thanks to the million, as always.

+4
source share
1 answer

Updated fiddle . I think this code should do this.

 $("#continue").click(function(){ $("table#ordertable > tbody > tr").each(function(){ var productVal = $('td:eq(0) input', this).val(); if(productVal.length > 0){ //get the code portion var trimmedProductVal = productVal.substring(0, productVal.length - 2); var productCode = productVal.substring(productVal.length-2, productVal.length); //get the checked items $('td.tdcheckbox', this).each(function(){ var currentCell = this; $("input[type='checkbox']:checked", this).each(function(){ //concatenate the value var valueToSet = $('input[type="text"]:eq(1)', currentCell).val(); valueToSet = trimmedProductVal + valueToSet + productCode; //set the text value $('input[type="text"]:eq(0)', currentCell).val(valueToSet); });; }); } }); }); 
+4
source

All Articles