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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Storing Variables

    In this code:
    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];
    	}
    }
    What would you write in a document.write function to display only one form value onto the other page. I'm pretty sure this has to use an external JS file.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,729
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    Change

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

    to

    i = the single element you wish to display
    theForm.elements[i].value = navigator.myvalues[theForm.elements[i].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
    •