Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I was wondering what I am d

Status
Not open for further replies.

niblet

Programmer
Aug 7, 2001
30
US
Hi,

I was wondering what I am doing wrong here, I want to be
able to generically save the contents of a form to a cookie, without hardcoding the names of the fields in my
code. I saw some examples where the script looped through
the elements of a form and extracted the information using
the for loop counter. I am trying this with the code below
and its not working, its says elements[..] is null or not an object. When i watch it in the debugger it says the element is null. However, when I keep the same code, but hard code a 0 or a 3 in the [arraycounter] so its elements[0] instead of elements[j] where j=0, then it works, but that certainly defeats the purpose of having a generic function. has this happened to someone else also ?
thanks .... code below

ps elements.length does report back the correct number of elements in the form. Its just inside the for loop using an icrementer that elements[..] is null

with(currentForm)
{
numElements = elements.length;
for(j=0; j<numElements; j++);
{
currentType = elements[j].type;
if(currentType == &quot;submit&quot; || currentType == &quot;SUBMIT&quot;)
{
//DON'T SAVE VALUE
}
else
{
currentName=elements[j].name;
currentValue=elements[j].value;
setCookie(currentName, currentValue);

}//else
}//for
}//with
 
How embarrassing ....

I got it, there's a semi colon after the for condition statement ... making the j value invalid in later statements. I didn't even see that until I read the posting again.... so it did help to write this, but no big mystery to be solved here, just tired eyes .....

thanks anyway
niblet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top