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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript loop help

    I have a drop down with 1-20 in it and I have it set to redirect with num=# in the browser then a file upload that appears that many times. I have it working fine but with php. The problem is that all the input added into the text boxes before that get erased since the page gets refreshed. I want to have the same functionality but without all the other input getting erased.

    All help would be appreciated
    Thanks

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    store the data in cookies. read the data from the cookie on request, and set field values/defaults accordingly. thus data won't be lost on refresh.
    *keep it simple (TM)

  • #3
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cant do it with cookies because no form has been submitted yet, they need to choose a number from the drop so that many file uploads appear, then they6 can choose the images and submit form. Isnt there any way to make the file uploads appear according to what number they selected in the dropdown with javascript

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Chronic669
    cant do it with cookies because no form has been submitted yet, they need to choose a number from the drop so that many file uploads appear, then they6 can choose the images and submit form.
    no, i meant to use cookies to maintain form state when the page was reloaded, ie you immediately write any changes to the cookie when they happen. That way you solve this:

    The problem is that all the input added into the text boxes before that get erased since the page gets refreshed. I want to have the same functionality but without all the other input getting erased.
    *keep it simple (TM)

  • #5
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    is there a way of doing this with javascript without the page reloading

    EDIT:

    ok I found out how to do it just one thing, how do you do loops in javascript, like
    PHP Code:
    while($n <= 20)
    {
    echo(
    'blah');

    Last edited by Chronic669; 03-12-2005 at 12:37 PM.

  • #6
    New Coder
    Join Date
    Aug 2004
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hi,

    I dont know exactly but check out if this may be of any help to you.

    Code:
    		function storeFormVals()
    		{
    			theForm = document.getElementById("someform");			myArray=new Array();
    			for (i=0;i<theForm.elements.length;i++)
    			{
    				myArray[theForm.elements[i].name] = theForm.elements[i].value;
    			}
    			navigator.somearray = myArray;
    		}
    
    		function restoreFormVals() 
    		{
    			theForm = document.getElementById("someform");
    			if (!navigator.somearray) return;
    
    			for (i=0;i<theForm.elements.length;i++)
    			{
    				theForm.elements[i].value = navigator.somearray[theForm.elements[i].name];
    			}
    		}
    It helps you to retain form values accross the pages within the same window.

    Do post if this works out...

    Afru.


  •  

    Posting Permissions

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