• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
enable/disable submit button based on my row table value

#1
I want to enable/disable submit button based on my row table 
Code:
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">    

    $('#mytable tr').each(function() {
   if (!this.rowIndex) return; // skip first row
   var customerId = this.cells[3].innerHTML;
   alert(customerId);  
});
</script>
 
if customerid ='failure';
disable submit button else enable. is this possible ?
Reply

#2
If i were you, i would definitely handle this in the function that is drawing the table.


Something like this:
PHP Code:
   <tbody>
 
       <?php foreach ($dataArray as $row): ?>
            <tr>
                <td><?= $row[0?></td>
                <td><?= $row[1?></td>
                <td><?= $row[2?></td>
                <td><?= $row[3?></td>
                <td>
                    <?php if ($row[3] == 'failure'): ?>
                        <button class="disabled"  disabled >Push Button</button>
                    <?php else: ?>
                        <button class="active" >Push Button</button>
                    <?php endif; ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </tbody> 
Reply

#3
You should do this by finding this button by id or class or if this is only one submit button on page by selector $('input[type=submit]');
Im not exactly know how your code should work with this customerId but i think you want to disable button when customerId gonna be empty?

Code:
$('#mytable tr').each(function()
{
  if (!this.rowIndex) return; // skip first row
  var customerId = this.cells[3].innerHTML;
  if(customerId == ''){  // Im understand that innerHTML return text value
     $('#mysubmitbtn').prop('disabled', true);
   }
});
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.