Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Dropdown values in a JavaSript array

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

Full Member

10+ Year Member

joined:Mar 7, 2003
votes: 0

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


[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)

Senior Member

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

joined:Mar 20, 2002
votes: 0

How many fields do you have to process?

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members