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 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    39
    Thanks
    4
    Thanked 0 Times in 0 Posts

    How do I capture a button array to turn them off and on?

    My screen displays any number of buttons at a time,
    up to 10.

    I turn them on or off using
    document.getElementById("butt1").style.display

    Some buttons must be hidden for a time, and then
    these same buttons must reappear.

    How do I "register" into an array
    those buttons that were previously on display,
    but now will be shut off,
    so I can traverse the array later, to turn them back on?

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    45
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Just put the ID's in an array? Then loop through the array and change the display using your same code:

    Code:
    document.getElementById(array[x]).style.display

  • #3
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Quote Originally Posted by bgallegos View Post
    Just put the ID's in an array? Then loop through the array and change the display using your same code:

    Code:
    document.getElementById(array[x]).style.display
    If he uses just that users that have css disabled will still be able to use the buttons.

    You will want to use something more like
    Code:
    function hideButtons(el){
         if(el.disabled == 'disabled')
              el.display='none';
         }else{
              el.display = 'block';
         }
    }
    You would use the code like this:
    Code:
    <script type="text/javascript">
    function hideButtons(el){
         if(el.disabled == 'disabled')
              el.display='none';
         }else{
              el.display = 'block';
         }
    }
    // this section will loop through all of your forms and hide the elements
    // that are initially set to disabled
    function check_forms(){
         var form = document.forms[0];
         for(i=0; i<form.elements.length;i++){
               hideButtons(form.elements[i]);
         }
    }
    </script>

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    39
    Thanks
    4
    Thanked 0 Times in 0 Posts
    ninnypanyts - I didn't quite understand your point about CSS being turned off at the user.

    Just to be sure you know what I do, though,
    let me say this:
    All my buttons are initially defined in the HTML;
    e.g., <input type='button' id='ringup' value='Ring it up' />

    Thereafter, javascript either turns them off, via
    document.getElementById("ringup").style.display = 'none';
    or on, via
    ... = 'block';

    I've now realized I can detect which are "Off" via
    if(document.getElementById('ringup').style.display=='none')

    OK, so I can now push all the id's of the On buttons onto an array,
    to later retrieve these id's, to shut these buttons Off.

    Now - where must I take heed in case the user has his CSS disabled,
    and why - again?

  • #5
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    If the user disables the css in their browser all of your form fields will become available to them even though you might want them to be unusable until later. So you would make the ones you didn't want to be used disabled with
    Code:
    <input type="text" disabled="disabled" />
    That will make the input boxes or whatever other from elements unusable until you change the disabled attribute to false. Then if you create a function out of the script I gave you it will cycle through all of the form elements in the specified form and hide the disabled form fields.ex:
    Code:
    <script type="text/javascript">
    function hideButtons(el){
         if(el.disabled == 'disabled')
              el.display='none';
         }else{
              el.display = 'block';
         }
    }
    // this section will loop through all of your forms and hide the elements
    // that are initially set to disabled
    function check_forms(){
         var form = document.forms[0];
         for(i=0; i<form.elements.length;i++){
               hideButtons(form.elements[i]);
         }
    }
    </script>
    </head>
    <body onload="check_forms();">
    Then once your form elements need to become avaliable you run your script to enable them and run this function again and they should become visible.

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I would rather create/remove the buttons with DOM methods whenever i need that. Tell us more about your project. What buttons? When to be shown? Must they be hidden again? When? can we see a HTML example?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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