...

View Full Version : javascript loop help



Chronic669
03-10-2005, 04:56 PM
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

jbot
03-10-2005, 05:22 PM
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.

Chronic669
03-10-2005, 05:28 PM
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

jbot
03-10-2005, 11:47 PM
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.

Chronic669
03-12-2005, 01:23 PM
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


while($n <= 20)
{
echo('blah');
}

afru
03-12-2005, 04:24 PM
Hi,

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



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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum