...

View Full Version : How do I capture a button array to turn them off and on?



ruffy
08-04-2008, 06:12 PM
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?

bgallegos
08-04-2008, 09:25 PM
Just put the ID's in an array? Then loop through the array and change the display using your same code:


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

ninnypants
08-04-2008, 10:18 PM
Just put the ID's in an array? Then loop through the array and change the display using your same 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


function hideButtons(el){
if(el.disabled == 'disabled')
el.display='none';
}else{
el.display = 'block';
}
}

You would use the code like this:


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

ruffy
08-05-2008, 01:15 PM
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?

ninnypants
08-05-2008, 03:38 PM
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


<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:


<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.

Kor
08-05-2008, 03:58 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum