jquery para recorrer la tabla, para cada fila y valores de concatonación td

I have a table with several rows. each row has a product field, a grade field and a family field.

There is then several checkboxes for each available size.

a row in the table looks like this:

<table class="authors-list" border=0 id="ordertable">
     <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 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 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><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>
<input type="button" id="continue" value="continue">

all fields will be hidden in end result besides the product field.

To give you a background, my product code looks like this: 3811460S5 38114 is the width and height 60 is the length Cr is the grade.

What I want to happen is that when I click the button, jquery must loop through all tables cells. where there is a CHECKED checkbox AND product has been populated, jquery must join the fields as below: skufamily(for row[skufamily])+length(from cell[size])+grade(from row[skugrade])

this result must populate the current td input line. so now each cell will have an exact sku (only if checked and product populated)

skufamily,size, and grade is prepopulated so just need the jquery to loop and join the fields.

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

I have tried the following concept but cant quite nail 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 +


This is far from correct so if you can put me on the right path I'd appreciate it.

Thanks a million as always.

preguntado el 23 de abril de 13 a las 13:04

¿Intentaste algo tú mismo? -

Thanks Limelights, I have updated the question with what I have but think I am on the wrong path... very much so... sorry new to jquery and coding in general. -

No need to apologize for being a beginner, just make sure you read our FAQ before posting. FAQ: stackoverflow.com/faq -

Thanks Limelights, will adhere to this more going forward. -

Cool beans, chief! :) -

1 Respuestas

Actualizado su violín. I think this code should do it.

    $("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);

Respondido 23 Abr '13, 15:04

Impressive. thanks Terence, I'll need to work through that to understand it but works perfectly. Appreciate your efforts. Thanks again. - JustStarting

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.