views:

83

answers:

2

Hello -

I have a table that is using jQuery to generate a "new row" when a button is clicked. When this new row is generated, new inputs are generated. Here is where I got the script from:

chris-barr[dot]com/projects/table_jquery

I am using this code on an order form for a client and I need to specifically target each "name" for the form processing part. The four that are static upon entering the page have "names" like this:

orderType1, orderType2, orderType3, orderType4

So, with each new row that is added, I need to append an incrementing name to each new input that is generated starting at orderType5 and maxing out at orderType10.

**I have max table rows set to 10.

here is my example:

http://www.tdidesign.com/designerorderform.php

I would appreciate any help or insight on how to get started with this. Thanks in advance.

+1  A: 

I see you are already using an array on orderType[].

Is there a reason you don't want to simply turn this into a multidimensional array?

<input name="entry[orderType][]" />
<input name="entry[sampleNeeded][]" />
<input name="entry[yardage][]" />
<input name="entry[pattern][]" />
<input name="entry[manufacturer][]" />

Since your POST data will come out in order on the backend you will have everything in perfect ordering for parsing.

cballou
I started to do so because I assumed I would need an array to accomplish this task but I had no luck getting it to work. I think my inexperience with JS is showing through...lol. Whats funny is that I know how to accomplish this with PHP and Actionscript but I can't seem to get it to work in JS! I think its maybe just a formatting issue or something. I appreciate your time. Thanks!
Jay
I am still having difficulty getting this going. I am still having syntax issues and passing the values off to each input as each new row is created. I have some JS books on the way but I still have to get this going. Any help would be greatly appreciated.
Jay
@Jay - Where are the values coming from? I would suggest you use a library like jQuery so you can easily get the number if inputs using something like `var numEntries = $('input[name^="entry[orderType').length`. You could then insert values based on the index of the new element, i.e. `$('input[name^="entry[orderType"]').eq(numEntries).val('yourvaluehere')`
cballou
I am using jQuery for adding new rows to a table that has 4 existing rows upon entering the page. So the existing rows have names like "sample1,sample2,sample3, and sample4. I have the max rows set to 6 (total of 10 rows), so when each new row that is created, I need the name "sample" to increment starting at "sample5" to "sample10". So, I was thinking I would just have to have something like: input name="sample[incrementing_number] and just pass a number to "incrementing_number" that would loop starting at 5 and increment til it hits 10.
Jay
A: 

I'm still messing around with this. Has anybody else have any suggestions?

Jay
What's the problem? Didn't cballou's solution work?
Tatu Ulmanen
I am more of a php guy, and I think I am having issues writing this in JS. I'm still new to the syntax and I think its my biggest problem right now. I still don't know what I need to write to pass the incremented value off to the newly created table row.
Jay