The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

But I also have a discount button that calculates a new price in javascript. And accessing the input field arrays using the following only works if there are more than one element in the array. IE if I have just one "price" input field, it doesnt work. If I have 2 or more, it works like a dream.

Code:

document.forms["book"].elements["price[]"][0].value

I guess it just isn't considered an array in javascript if there is only one element.

Again, this all works fine as far as the processing in php, no matter how many "price" input fields I have, even just one.

Does anyone know of a work around for this?

I suppose I could code it to use name="price1", name="price2", etc but I was hoping to use arrays. Much cleaner.

The name of the element doesn't need to have [] to be an array...
If you use <input name="price" value="10"><input name="price" value="20">, then
document.forms["form"].elements["price"]
will still return an array (this is just a FYI).

Your code isn't that hokey You could just use
if( document.forms["form"].elements["price"].length ) {
blah;
} else {
blah;
}
but your way will be ok too.