homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

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

 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


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

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