[jQuery] iterating over unknown number of objects
Hi everybody,
I'm just starting with jquery so I hope this is not a stupid question...
I have a big form and there can be two similar input or select fields. To
differentiate these, I want to add n ID at the and of all name attributes of
the text fields and select boxes.
I want to add this function to the submit button, so when I submit the form,
i get the new names.
A short example... If I generate this form, all name attributes are
"textfield" without any number at the end, so I just want to display what I
expect...
<form id="myForm" action="/cgi-bin/webinterface.py" method="post">
<!-- <input type="checkbox" name="bif" value="bif"> BIF <br /> -->
<div id="interface">
<div class="querydiv">
<input type="text" name="textfield_1" />
<input type="text" name="textfield_1" />
</div>
<div class="querydiv">
<input type="text" name="textfield_2" />
<input type="text" name="textfield_2" />
<input type="text" name="textfield_2" />
<div class="querydiv">
<input type="text" name="textfield_2_1" />
</div>
<div class="querydiv">
<input type="text" name="textfield_2_2" />
<input type="text" name="textfield_2_2" />
</div>
</div>
<div class="querydiv">
<input type="text" name="textfield_3" />
<div class="querydiv">
<input type="text" name="textfield_3_1" />
<div class="querydiv">
<input type="text" name="textfield_3_1_1" />
<div class="querydiv">
<input type="text" name="textfield_3_1_1_1" />
<div class="querydiv">
<input type="text" name="textfield_3_1_1_1_1" />
<input type="text" name="textfield_3_1_1_1_1" />
</div>
<input type="text" name="textfield_3_1_1_1" />
<input type="text" name="textfield_3_1_1_1" />
</div>
<div>
<input type="text" name="textfield_3_1_1_2" />
<input type="text" name="textfield_3_1_1_2" />
</div>
<input type="text" name="textfield" />
<input type="text" name="textfield" />
</div>
<input type="text" name="textfield" />
<input type="text" name="textfield" />
</div>
</div>
<input type="button" id="submit" value="Submit Query" />
</form>
I wrote this down by hand, so I hope there are no typos :-)
I already tried something with the select $("#interface").children().each()
and I could rename the name attributes for the first child's, but I have
problem to do this in an unknown level of interlace (hope this is the right
word).
So maybe anyone can help me to create this loop and to create this
counter...
I thought about a var idcount = new Array; and then add a new int to the
idcount array, so i had a counter for the first level idcount[0], for the
second level idcount[1] and so on.
hope someone could help me...
--
View this message in context: http://www.nabble.com/iterating-over-unknown-number-of-objects-tp16001328s27240p16001328.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.