1

I understand that you do something like:

$('form').append('<input type="text" name="color-1" value="Hello" />');

But I have two questions about it. First off, I don't want it added to the end of the form, but after the last input in the "color" section. Secondly, where "name=color-1", I need the one to increment if they want to add more than one input, you know? So that I can process it on the server.

Any ideas?

2
  • One idea would be to learn some basic javascript. Commented Apr 15, 2010 at 3:42
  • As blunt is fig-gnuton is, he's actually right. It won't take you too long. Commented Apr 15, 2010 at 4:48

1 Answer 1

2

I guess what you are looking for is the .after() // .insertAfter() function. Let's say you have a DIV with the class "color" within your form, you would do

$('form').find('.color > :input').last().after('<input type="text" name="" value=""/>');

To add more of those input fields, just add a button or anything else which is capable of executing a click event, where you can execute code to insert more inputs.

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

1 Comment

A slight adjustment to the selector (if I understand the question right) would be $('form').find(':input[name*=color]').last()

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.