Welcome Guest, Not a member yet? Register   Sign In
getElemntbyid returns undefined value
#10

What's the point in getting elements by id if the id's are dynamic?
Instead, use a css class as the selector. Then, use the $(this).parents('tr') method to get the row in the table.

Example:
PHP Code:
<table>
 
 <?php foreach($rows as $row) : ?>
      <tr>
        <td><input type="text" name="text_one[]" class="findrow" /></td>
        <td><span class="showme"><?= $row['id'];?></span></td>
     </tr>
  <?php endforeach; ?>
</table> 

Code:
<script>
$(document).ready(function(){
  $('.findrow').change(function(){
     row = $(this).parents('tr');
     t2 = row.find('.showme').html();
     alert(t2);
  });
});
</script>

After you change the value in one of the input fields, the id of the current row will be displayed in an alert box.
Reply


Messages In This Thread
RE: getElemntbyid returns undefined value - by Wouter60 - 08-29-2018, 10:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB