...

View Full Version : Using JavaScript with Forms



TravisMath
03-14-2005, 11:16 PM
Is there a way to permanently save form results inside a script?

glenngv
03-15-2005, 03:51 AM
If you really want to permanently save the form results and retrieve them at a later time, you need to store them in a database, so you need a server-side language for that. You can store limited data in a cookie but cookies can be easily deleted by users. So your best bet is to store them in a database.

afru
03-15-2005, 04:07 PM
Hi TravisMath,

As glenngv has stated, If you want to permanently save form values, you need to save to database using serverside code. If you want to use javascript, you can use the below code to save form values that will be available till you close the window. That means you can save form values in one page and use them on another also.



function storeFormVals()
{
theForm = document.getElementById("formname");
myArray=new Array();
for (i=0;i<theForm.elements.length;i++)
{
myArray[theForm.elements[i].name] = theForm.elements[i].value;
}
navigator.myvalues = myArray;
}

function restoreFormVals()
{
theForm = document.getElementById("formname");
if (!navigator.myvalues) return;

for (i=0;i<theForm.elements.length;i++)
{
theForm.elements[i].value = navigator.myvalues[theForm.elements[i].name];
}
}



Have a nice day :)

Afru.

TravisMath
03-18-2005, 01:37 AM
To get just one value out of the array would you type

document.write(navigator.myvalues[theForm.elements[i].name];);

Thanks again

TravisMath
03-18-2005, 02:05 AM
I meant
document.write(navigator.myvalues[theForm.elements[1].name]



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum