Limit the number of rows to 10 of my 'Add Row' function

I need to limit the number of rows I add to 10 in this function.
Thanks!
						$(document).on('click','#addAddOnDay',function(){
							var rowCount = $('#addOnDay tr').length + 1;
							var rowClass = (rowCount % 2 != 0) ? 'rowOdd' : 'rowEven';
							$('#addOnDay').append('<tr class="'+ rowClass +'"> \
																						<td align="center"><input type="text" class="text" style="width: 99%;" /></td> \
																						<td align="center"><input type="radio" name="4a_1"> <label>Yes</label> &nbsp; <input type="radio" name="4a_1" checked> <label>No</label></td> \
																						<td align="center">20000 or 95%</td> \
																						<td align="center" class="rollUpDisplay">1</td> \
																					</tr>');
						});

Open in new window

LVL 1
capturetheflagAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Something like this:

$(document).on('click','#addAddOnDay',function(){

var rowCount = $('#addOnDay tr').length + 1;

if (rowCount > 10) {
    alert("You can't add any more rows!");
} else {
    //add new rows here
};

});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
(no points) just putting it together for you:

$(document).on('click','#addAddOnDay',function(){
	var rowCount = $('#addOnDay tr').length + 1;
	if (rowCount > 10) {
		alert("You can't add any more rows!");
	} else {
		var rowClass = (rowCount % 2 != 0) ? 'rowOdd' : 'rowEven';
		$('#addOnDay').append('<tr class="'+ rowClass +'"> \
			<td align="center"><input type="text" class="text" style="width: 99%;" /></td> \
			<td align="center"><input type="radio" name="4a_1"> <label>Yes</label> &nbsp; <input type="radio" name="4a_1" checked> <label>No</label></td> \
			<td align="center">20000 or 95%</td> \
			<td align="center" class="rollUpDisplay">1</td> \
			</tr> \
		');
	};
});

Open in new window

0
capturetheflagAuthor Commented:
Hello Chris and tagit,

Thanks for the help.  I have to change rowCount > 10, to rowCount > 11 in order to get 10 rows. rowCount > 10 just gave me 9 rows.  Is there a reason for this? rowCount >= 10 gave me just 9 rows too.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Chris StanyonWebDevCommented:
Not sure really. It should give you ten rows. If you use >= 10, then you'll only get 9, but using > 10 should give you 10. Maybe it's because you add 1 to the rowCount for some reason. Here's a fiddle that shows it working:

http://jsfiddle.net/ChrisStanyon/Kj4yH/

I can take more of a look if you post your code (including the HTML) or preferably give us a link to a page that demonstrates the problem.
0
capturetheflagAuthor Commented:
Thanks for the help
0
Chris StanyonWebDevCommented:
Agree with @tagit - the answer posted was pretty much a copy and paste answer so can't understand why it's only a B
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.