homepage Welcome to WebmasterWorld Guest from 54.158.103.233
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Dropdown values in a JavaSript array
natty

10+ Year Member



 
Msg#: 773 posted 11:45 am on Mar 18, 2003 (gmt 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

nathan

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

 

korkus2000

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



 
Msg#: 773 posted 12:33 am on Mar 21, 2003 (gmt 0)

How many fields do you have to process?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved