user552828
user552828

Reputation: 769

stopping my function on javascript

http://jsfiddle.net/jaredwilli/tZPg4/4/

here I can add and remove unlimited inputs on my page.

My question is how can I make this function to produce maximum 6 more inputs then hiding the "Add Another Input Box" link.

I am a newbie. This question must be really easy for javascript programmers.

Upvotes: 1

Views: 158

Answers (3)

nrabinowitz
nrabinowitz

Reputation: 55678

See: http://jsfiddle.net/nrabinowitz/38RE6/7/

This implements what everyone else suggested - check the i counter variable, and hide the link when necessary. Note that you had an error in your code - you can't add multiple elements with the same id attribute, so I had to change id="remScnt" to class="remScnt" and change the corresponding selector.

Upvotes: 2

Ilia G
Ilia G

Reputation: 10221

You already keeping track of the input count in your i variable. What stops you from just adding if(i>=6)return false; first thing in your click handler?

Upvotes: 0

SLaks
SLaks

Reputation: 887797

After incrementing i, you want to check if (i >= 6) and .hide() the add link.

You probably want to .show() it again whenever you remove an input. (if it's already visible, .show() won't do anything).

Upvotes: 2

Related Questions