Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-04-2008, 06:12 PM   PM User | #1
ruffy
New Coder

 
Join Date: Jul 2008
Posts: 39
Thanks: 4
Thanked 0 Times in 0 Posts
ruffy is an unknown quantity at this point
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?
ruffy is offline   Reply With Quote
Old 08-04-2008, 09:25 PM   PM User | #2
bgallegos
New Coder

 
Join Date: Jul 2008
Posts: 45
Thanks: 0
Thanked 6 Times in 6 Posts
bgallegos is an unknown quantity at this point
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
bgallegos is offline   Reply With Quote
Old 08-04-2008, 10:18 PM   PM User | #3
ninnypants
Regular Coder

 
ninnypants's Avatar
 
Join Date: Apr 2008
Location: Utah
Posts: 504
Thanks: 10
Thanked 47 Times in 47 Posts
ninnypants is an unknown quantity at this point
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>
ninnypants is offline   Reply With Quote
Old 08-05-2008, 01:15 PM   PM User | #4
ruffy
New Coder

 
Join Date: Jul 2008
Posts: 39
Thanks: 4
Thanked 0 Times in 0 Posts
ruffy is an unknown quantity at this point
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?
ruffy is offline   Reply With Quote
Old 08-05-2008, 03:38 PM   PM User | #5
ninnypants
Regular Coder

 
ninnypants's Avatar
 
Join Date: Apr 2008
Location: Utah
Posts: 504
Thanks: 10
Thanked 47 Times in 47 Posts
ninnypants is an unknown quantity at this point
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.
ninnypants is offline   Reply With Quote
Old 08-05-2008, 03:58 PM   PM User | #6
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:19 PM.


Advertisement
Log in to turn off these ads.