View Full Version : Help with Form object

07-01-2005, 03:27 AM

I'm encountering some problem with Form object.
I have a form named KPIIN. In the form,
I'm having 2 input field with type=text in the body.
I gave the first textbox name=txtinput, id=txt1
and the second textbox name=txtinput, id=txt2.

In my body tag, I have onload=loodcookie() function.
And in my function, I just want to alert a single line


So, when I run my page, I will received a popup returning
2, which is the number of element in my body page. This is

However, when I take out one of the textbox and leave
only a single textbox, this alert message return "Undefined"

Should it returns "1"?

Any help is greatly appreciated. Thanks in advance.

07-01-2005, 04:25 AM
Should it returns "1"?

No. When there's only one control with a particular name, there is no collection or array formed (unlike when there are two or more same named controls). That's why there's no length property.

When there's only one field with that name, you access it without an index


Unlike with a collection:


Take note of the document object. Your direct access to form will only work with IE.

07-01-2005, 05:11 AM
Thanks glenn,

That's what I think so. But however, in my page, the textboxes are generated dynamically. I wanted to control these textboxes to that
not all user can see the same number of them.

Therefore, I need to get the count of textboxes on the screen to enable
me to set the condition. In this case, I'm using the KPPIN.txtinput.length
to return me the count of textboxes. So, if there's only one textbox in the
screen, what is the way for me to know, if the KPIIN.txtinput.length is
not applicable?

07-01-2005, 05:32 AM
var txt = document.KPIIN.txtinput;
if (txt.length){ //length property is supported so it means there are 2 or more fields
for (var i=0; i<txt.length; i++){
else { //there's only one textbox

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum