Search code examples
javascriptjqueryhtmljavascriptserializerdynamic-html

Retrieve all values of a dynamically generated html table


I have a html table displayed in a showmodal dialog window, the html-body has several divs, each div having several tables, tr and td within them.

The user will update entries within the input tag so i need to capture the change.

One such div looks like below. How to I retrieve all these values on a button click. I have heard of serialize() method. Will it work for all tag types, "insert","select", "option" etc etc.

<div>
  <table>
    <tr><td></td><td></td><td></td>
    </tr>
  </table>
  <table>
    <tr><td></td><td></td>
    </tr>
    <tr><td></td><td></td><td></td><td></td>
    </tr>
  </table>
  <table>
    <tr><td></td>
    </tr>
  </table>
</div>

Solution

  • Apologies, writing my solution in a pseudocode fashion:

    //I created a div container and then loop through all the divs

    //then retrieve values using one of the below

        $("classname > div[id]").each(function(){
    
          var a=   document.getElementsByName("name of the tag");   //by name
          var b=   document.getElementById("id of the tag");      //by id
          var c=   $("input[class='"+trd_id+"']:checked").val();     // for radio button
    
        });
    

    // loop by div counts and alert the values. Solved my problems