jQuery to populate array-named form fields based on first entered value where number of fields is un
Posted
by da5id
on Stack Overflow
See other posts from Stack Overflow
or by da5id
Published on 2010-04-13T00:42:14Z
Indexed on
2010/04/13
1:12 UTC
Read the original article
Hit count: 497
Greetings,
I have a form with a variable number of inputs, a simplified version of which looks like this:
<form>
<label for="same">all the same as first?</label>
<input id="same" name="same" type="checkbox" />
<input type="text" id="foo[1]" name="foo[1]" value="" />
<input type="text" id="foo[2]" name="foo[2]" value="" />
<input type="text" id="foo[3]" name="foo[3]" value="" />
<input type="text" id="foo[4]" name="foo[4]" value="" />
<input type="text" id="foo[5]" name="foo[5]" value="" />
</form>
The idea is to tick the #same checkbox and have jQuery copy the value from #foo[1] into #foo[2], #foo[3], etc. They also need to clear if #same is unchecked.
There can be any number of #foo inputs, based upon input from a previous stage of the form, and this bit is giving me trouble. I'm sure I'm missing something obvious, but I can't get any variation on $('#dest').val($('#source').val());
to work.
Help!
© Stack Overflow or respective owner