Monday 26 February 2018

Get row Index and value inside the table control click on button using jquery

////////////// HTML

<table id="gridid">
  <thead>
    <tr class="ui-widget-header ">
      <th>Head1</th>
      <th>Head2</th>
      <th>Head3</th>
      <th>Head4</th>
      <th>Head5</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><input type='textbox' class="buttoncss"/></td>
      <td><input type='textbox' class="buttoncss"/></td>
      <td><input type='textbox' class="buttoncss"/></td>
      <td><input type='textbox' class="buttoncss"/></td>     
    </tr>
    <tr>
      <td><input type='textbox'/></td>
      <td><input type='textbox'/></td>
      <td><input type='textbox'/></td>
      <td><input type='textbox'/></td>    
    </tr>
  </tbody>
</table>



//////////////////////////// js

<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>

$(document).ready(function(){
           $(".buttoncss").change(function () {
               var vv = $(this).val();
               //alert(vv);
               var $row = $(this).closest("tr");    // Find the row
               var rn = $row.index() + 2
               //  alert(rn);
               $('#gridid tr').eq(rn).find('td').each(function () {
                   $(this).find('input').each(function () {
                       if ($(this).is('input[type="textbox"]')) {
                           $(this).val(vv);
                           // var textval = $(this).val();
                           //  alert(textval);
                       }
                   });
               });

               //$(this).closest('tr').find('td').each(function() {
               //     var textval = $(this).text();
               //     alert(textval);
               // });
           });
       });

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...