0

I am taking the amount from one input box and creating a for...each loop to add input boxes. But I have run into a problem. I tried using append() and html() - append() keeps adding more boxes than needed and html() only adds the last one. Which are both correct. But I need the input boxes to be exactly what the amount is. And if the input box changes again, I need it to re update.

here is the jsfiddle: http://jsfiddle.net/liveandream/mRY3d/

I hope this makes sense... and hopefully someone can help me!! Thanks in advance..

3
  • I entered 4 in your jsFiddle and saw 2 sets of inputs show up. Isn't that what should show up? I'm not sure I understand what your problem is then. Commented Mar 30, 2012 at 22:46
  • If you change the number of children, it's appending a whole new set of boxes instead of replacing the old ones. Commented Mar 30, 2012 at 22:56
  • Please have a look at my solution and see if it fits your needs better. Thanks! Commented Mar 31, 2012 at 3:32

2 Answers 2

1

You probably want to add:

$('.extrakids').empty();

Right before your for loop;

Sign up to request clarification or add additional context in comments.

Comments

0

http://jsfiddle.net/iambriansreed/mRY3d/22/

My answer solves a lot of issues.

If you add or remove children you don't overwrite boxes and lose any data put in those boxes.

The update is timed out so if a user slips the JS loop won't crash if it tries to make too many. I maxed out the children created as well.

I left the html where it belonged and created the inputs from it.

And I fixed the original issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.