PDA

View Full Version : Need help with disable



ShadowIce
04-27-2009, 04:54 PM
Hi everybody.

Could someone help me make it so this script disables all buttons and textareas and stuff BESIDES whats in the function named "on()" ?

for example

if theres 2 buttons in on, a button named "one" and a button called "2", it will disable EVERYTHING BUT the buttons one & two


function on(){
disableForm(document.forms.calculator.one);
disableForm(document.forms.calculator.two);
}

function disableForm(thename) {
var numberForms = document.forms.length;
var formIndex;
for (formIndex=0; formIndex<numberForms; formIndex++)
{
for(x=0;x<document.forms[formIndex].length;x++)
if(document.forms[formIndex].elements[x] +== thename){
document.forms[formIndex].elements[x].disabled=false
}else{
document.forms[formIndex].elements[x].disabled=true
}
}
}

thank you!

~Shadow~

jscheuer1
04-27-2009, 05:27 PM
function on(){
disableForms({one: 'calculator', two: 'calculator'});
};

function disableForms(exceptions){
var numberForms = document.forms.length, formIndex = 0, x, n;
for (formIndex; formIndex < numberForms; ++formIndex){
for (x = 0; x < document.forms[formIndex].elements.length; ++x){
n = document.forms[formIndex].elements[x].name;
if (exceptions[n] && exceptions[n] === document.forms[formIndex].name){
document.forms[formIndex].elements[x].disabled = false;
}
else {
document.forms[formIndex].elements[x].disabled = true;
}
}
}
};