The reason why I don't want anyone adding more than 250 fields is because if they were to go over that amount, 251 and so on would not get entered into the mysql db. I know some people will probablly be thinking, why would I have such a large table? Well I don't really want to go into that and that would be going off topic, lol.
Well here's how I have the code: --- code --- (function($) { // Add repeat method to String object String.prototype.repeat = function(n){ return new Array(n + 1).join(this); }; // Add leading_zeros method to jQuery $.leading_zeros = function(n, total_digits){ n = n.toString(); return '0'.repeat(total_digits - n.length) + n; }; })(jQuery); $(document).ready(function(){ // initialize the counter var counter = 10; $('#fields-button').click(function(){ // increment and pad the counter var padded_counter = $.leading_zeros(++counter, 3); // create the new field var extrafield = '<tr><td>List Item #' + padded_counter + '</td><td>'; extrafield += '<input type="text" name="x_c' + padded_counter + '"' ; extrafield += ' id="x_c' + padded_counter + '"' ; extrafield += ' title="" size="30" maxlength="255"' ; extrafield += ' value="" </td></tr>'; // add the new field to the table $('#fields').append(extrafield); }); }); --- code --- Checking the value after each increment sounds like a good approach. > Two possibilities come to mind. Create an object that checks > itself as it changes or just check the value after each increment. > I tend to lean toward objects, but they tend to take more time to > write. Knowing the context of the limitation (or cap) would help a > lot. > > HTH, > > Charles K. Clarkson > -- > Mobile Homes Specialist > Free Market Advocate > Web Programmer > > 254 968-8328 > > http://www.clarksonenergyhomes.com/wordpress/about/