Read All Controls value from table

Read All controls value from table

by chidambaram k

HTML

<table id="table1" border="1">
   <tr>
      <th>EmployeeID</th>
      <th>Name</th>
      <th>Designation</th>
      <th>Process1</th>
      <th>Process2</th>
   </tr>
   <tr>
      <td>
         <input type="hidden" id="a1" class="firstName" value="1">
         0000011
      </td>
      <td>
         chidambaram
      </td>
      <td>
         Tech Lead
      </td>
      <td>
         <input type="hidden" id="a1" class="firstName" value="11">
         <input type="text" id="a1" class="firstName" value="text1">
      </td>
      <td>
         <input type="hidden" id="a1" class="firstName" value="22">
         <input type="text" id="a1" class="firstName" value="text2">
      </td>
   </tr>
   <tr>
      <td>
         <input type="hidden" id="a1" class="firstName" value="2">
         0000002
      </td>
      <td>
         Suresh
      </td>
      <td>
         Android Developer
      </td>
      <td>
         <input type="hidden" id="a1" class="firstName" value="33">
         <input type="text" id="a1" class="firstName" value="text3">
      </td>
      <td>
         <input type="hidden" id="a1" class="firstName" value="44">
         <input type="text" id="a1" class="firstName" value="text4">
      </td>
   </tr>
</table>
<button id="target">Click me</button>

JavaScript

$("#target").click(function() {

    //storage        
    var data = {
        firstName: [],
        lastName: []
    }

    //loop through the td's
    $('table tr').each(function() {

        var tdlen = $(this).children('td').length
        var i = 0;

        $('td', this).each(function() {


            if (i == 0) {
                alert('Emp. ID is : ' + $(this).find("input[type='hidden']").val());
            }
            if (i > 2) {
                alert('ID is : ' +$(this).find("input[type='hidden']").val());
                alert('text value is : ' +$(this).find("input[type='text']").val());
            }
            i++;
        });

    });



});