Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Using JavaScript with Forms

    Is there a way to permanently save form results inside a script?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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.

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    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.

  • #4
    New Coder
    Join Date
    Mar 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    To get just one value out of the array would you type

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

    Thanks again

  • #5
    New Coder
    Join Date
    Mar 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I meant
    document.write(navigator.myvalues[theForm.elements[1].name]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •