views:

35

answers:

2

I am populating a table based on a javascript function. I want to limit the data entered to 2, afterwhich I hide the table. Is there a way to track how many hits the javascript code gets hit?

function addNewRow() {
    $('#displayInjuryTable tr:last').after('<tr><td style="font-size:smaller;" class="name"></td><td style="font-size:smaller;" class="address"></td></tr>');
    var $tr = $('#displayInjuryTable tr:last');
    var propertyCondition = $('#txtInjuryAddress').val();


    $tr.find('.name').text($('#txtInjuryName').val());
    if (propertyCondition != "") {
        $tr.find('.address').text($('#txtInjuryAddress').val() + ', ' + $('#txtInjuryCity').val() + ' ' + $('#txtInjuryState').val() + ' ' + $('#txtInjuryZip').val());
 }
+2  A: 
var someCounter = 0

function addNewRow() {
  if(someCounter>1) {
    return
  }   
  someCounter++
 ...your code...
}
Diodeus
you need to hide the table before the "return" per OP specification.
Mark Schultheiss
A: 

var addNewRow = (function(){ var count = 0; return function(){ if (++count === 2) { //hide feature return; } ... // your code here } })();

Sean Kinsey