Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    New - passing lists as arguments

    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';
    }
    }
    }
    Last edited by glucose; 11-07-2006 at 11:46 AM.

  • #2
    New to the CF scene
    Join Date
    Nov 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb

    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';
    }
    }
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •