Click to See Complete Forum and Search --> : Referencing form elements that were added using appendChild


McDave
03-12-2004, 02:29 PM
Hi,

I'm building an interactive form that will convert CMY color values to RGB. The form starts with no input capabilities but each time you select "add form objects" from the web page, it will adds a row of input boxes to a table. There is no limit to the number of rows you can add. The idea is that you add the CMY values to the first set of boxes in the row, click convert and the RGB values appear in the second set of boxes in the row and a box of the selected color appears to the right of the RGB values.

The new form elements are added to the <TBody> tag using createElement() and appendChild(). Since input text elements of a certain color will all be named the same, say "Cyan", my understanding of javascript is that it will create an array of "Cyan" form object that can be referred to as Cyan[0], Cyan[1] ..etc. Adding the rows works fine and is not the problem.

When trying to convert the values, I want to find out how many rows have been added. Given that, and if the name of the form object is "convert", I should be able to get the length of that array and therefore the number of "Cyan" input boxes by the following reference:
document.convert.Cyan.length ;


When running this on IE 6, I get the following error message: "document.convert.Cyan.length is null or not an object".

When running it on Opera 7, it works like a charm!

Anyone have any ideas??

Thanks in advance.

Khalid Ali
03-12-2004, 07:24 PM
show us some code snippet that exactly has this functionality(better point to a url where you ahve this page).

it should not be too hard. it sounds like you already have done the hard part

McDave
03-13-2004, 11:44 AM
Thanks for agreeing to look at my code. I cleaned it up a little and posted it here:
http://www.celticweb.com/users/davemcmicken/experimental/ColorConverter/

Since I never completed it, I never cleaned up the useless code that's floating around. There are a few functions and lines that do nothing so just ignore them. The function to be concerned with are:

- addFormObjects() - adds the form objects.
- textColors(colorName) - creates the form objects
- function Convert(formObj) - Error on first line.

The error I get on internet explorer is :

"document.convert.Cyan.length is null or not an object"

which is the first line in the Convert() function.
Since the page isn't done, there is no form verification and a few annoying bugs. I put a few instructions on the page to help you avoid those.

Thanks again and I look forward to your comments.