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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need example of Loop + explaination how to use 1

Status
Not open for further replies.

WhiteTiger

Programmer
Jun 26, 2001
605
US
I dont use javascript much, but I'm using it to write cookies for office documents that need to be saved...

Right now, I have these functions...

function SaveForm() {
SetCookie ('t1', document.myform.t1.value);
SetCookie ('t2', document.myform.t2.value);
SetCookie ('t3', document.myform.t3.value);
}

function WriteCookie() {
document.myform.t1.value = GetCookie('t1');
document.myform.t2.value = GetCookie('t2');
document.myform.t3.value = GetCookie('t3');
}

How can I get it to loop through these (going 1 through 9), pick up the document.myform.tX.value with X being variable?...and same with get write cookie function... Regards,
Anth:cool:ny
 
Ok, with some work, I've gotten to this point...

function SaveForm() {
for (i = 1; i <= 9; i++)
{
SetCookie ('t' + i, document.myform.t(i).value);
}
}

For some reason, I have text forms, t1, t2, t3...all the way down to t9...but for some reason it doesn't like the way its implemented...somethings weird with it.

It happens when I try to run it, I get an &quot;Object Doesn't support property or method&quot; message...HOW can I implement this to increment the tX value? I need it basically to run through my form, save all the stuff in a cookie, and then later be able to retreve it all.

Also, how would I possibly delete ALL cookies for a page? Regards,
Anth:cool:ny
 
p.s. Since this stupid forum doesn't allow editing of threads or deletion.....

When I try to run the SaveForm function, it says Object doesn't support property of method.

How can I fix this?!...any gurus out there?!

Regards,
Anth:cool:ny
 
I think you want :

function SaveForm() {
for (var i = 1; i<9; i++) {
SetCookie('t'+i, document.myform['t'+i].value);
}
} Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
Thank you!...I think I remember trying something like t and it telling me t.1 wasn't a valid object...it all makes sense now...=) Regards,
Anth:cool:ny
 
Try

function SaveForm()
{
var txt;
txt = &quot;&quot;;
for (var i = 1; i < 9; i++)
{
txt = &quot;t&quot; + i;
SetCookie(txt, document.myform[txt].value);
}
}
 
yours is the same thing as BBD's...only more complicated and longer, and more confusing. Regards,
Anth:cool:ny
 
I didn't see BBD's at the time I posted but if you got a solution and its even better then thats great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top