...

View Full Version : New - passing lists as arguments



glucose
11-07-2006, 12:06 PM
Very new to javascript, appreciate any help I can get. Trying to pass a list e.g. showHideSwitchAll( 'a', 'b', 'c', 'd' ... ). Here, I want the act of calling this function to close all individual collapsible menus etc. ( 'a', 'b', 'c', 'd' ... ), which works under individual cases.

The function showHideSwitchAll is what I've tried. The individual function call is listed further below and uses document.getElementById. I looked up the documentation for document.getElementById, so I tried iterating through the arguments object, but maybe I'm missing something as a noob.

(showSwitch and hideSwitch is the css label)
menus_array = new Array ();
menus_status_array = new Array ();// remembers state of switches
img_close = 'expandbutton-close.gif';
img_open = 'expandbutton-open.gif';

function showHideSwitchAll () {

for ( var i = 0; i< arguments.length ; i++ ) {

var switch_id = arguments[i];
var imgid = arguments[i]+'Button';
var button_id = arguments[i];
if (menus_status_array[arguments[i]] != 'hide') {

button_id.setAttribute ('src', img_open);
switch_id.className = 'hideSwitch';
menus_status_array[arguments[i]] = 'hide';
}else{

button_id.setAttribute ('src', img_close);
switch_id.className = 'showSwitch';
menus_status_array[arguments[i]] = 'show';
}

}
}

Individual menu collapsing:

function showHideSwitch (theid) {

if (document.getElementById) {

var switch_id = document.getElementById(theid);
var imgid = theid+'Button';
var button_id = document.getElementById(imgid);
if (menus_status_array[theid] != 'hide') {

button_id.setAttribute ('src', img_open);
switch_id.className = 'hideSwitch';
menus_status_array[theid] = 'hide';
}else{

button_id.setAttribute ('src', img_close);
switch_id.className = 'showSwitch';
menus_status_array[theid] = 'show';
}
}
}

glucose
11-07-2006, 12:58 PM
this just about did it.

function showHideSwitchAll () {

for ( var i = 0; i< arguments.length ; i++ ) {

var switch_id = document.getElementById(arguments[i]);
var imgid = document.getElementById(arguments[i]) +'Button';
var button_id = document.getElementById(arguments[i]);
if (menus_status_array[arguments[i]] != 'hide') {

button_id.setAttribute ('src', img_open);
switch_id.className = 'hideSwitch';
menus_status_array[arguments[i]] = 'hide';
}else{

button_id.setAttribute ('src', img_close);
switch_id.className = 'showSwitch';
menus_status_array[arguments[i]] = 'show';
}
}
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum