Welcome to WebmasterWorld Guest from 54.167.155.147

Forum Moderators: open

Message Too Old, No Replies

Dropdown values in a JavaSript array

   
11:45 am on Mar 18, 2003 (gmt 0)

10+ Year Member



hi all,

me again with an annoying JS problem

i have some select dropdowns for which i need to save the option values for when i submit the page..
so i have done it like this. called from the onsubmit of the form.
two arrays hold the names of the dropdown fields, and the hidden ones to save to ..
but it falls over on like the 4th field im processing..
any ideas ..
this is driving me spare..

function saveVals(){
//this is used to save the values from the selected for a back button press
var i,x,theField,saveField;
var fieldsToSave = new Array ('selOutFrom', 'selOutTo', 'selOutYear', 'selOutMonth', 'selOutDay', 'selOutTime','selRetFrom', 'selRetTo', 'selRetYear', 'selRetMonth', 'selRetDay', 'selRetTime');
var saveFields = new Array ('saveOutFrom','saveOutTo','saveOutYear','saveOutMonth','saveOutDay', 'saveOutTime','saveRetFrom','saveRetTo','saveRetYear','saveRetMonth','saveRetDay', 'saveRetTime');
for (i = 0;i<fieldsToSave.length;i++){
saveField = '';
var savedVals = new Array();
theField = '';

theField = eval('document.forms[0].' + fieldsToSave[i]);
for (x = 0;x < theField.length;x++){
savedVals[x] = [theField.options[x].value, theField.options[x].text];
if(x == theField.options.length-1){savedVals[x] = theField.selectedIndex;}
}
saveField = eval('document.forms[0].' + saveFields[x]);
var fred = savedVals.join('+');
saveField.value = fred;
}
}

many thanks as always

nathan

[edited by: korkus2000 at 12:32 am (utc) on Mar. 21, 2003]
[edit reason] Fixed side scroll [/edit]

12:33 am on Mar 21, 2003 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



How many fields do you have to process?