views:

50

answers:

1

I'm programming an order form that has multiple order items. Each line item is a row in form, identical to the previous row. I'm wondering what the convention for names and ids on the input fields. Do i use the same names and id for the fields in each row?

How do I reference an input field within a particular form row?

How do i reference the rows of the form as an array?

What's the best programming approach?

for example:

item quantity item_price total_price item quantity item_price total_price item quantity item_price total_price

thanks

+2  A: 

I usually add the line number before/after it so that if I need reference it for AJAX and such, it has a unique name.

IPX Ares
do you add the line number to each id or as a separate hidden field on each row?
sdfor
To each id, so for row 1 you'd have item1 quantity1 item_price1 total_price1. Looping on them can then be done using getElementById('item' + i) where i is the incrementing number.
JShumaker
Having an id start with a number violates the w3c spec. http://www.w3.org/TR/html4/types.html#h-6.2
seth
true Seth, so after, and yes like JShumaker shows.
IPX Ares