...

View Full Version : 50% working



h8ids
05-02-2006, 10:48 PM
I'm trying to get the following code to activate and deactivate one form field by using one button.
Activating the field works. De-activating it is not.



function enableQ1(){
if (Department="disabled"){
document.form1.Department.disabled=false;
} else
if (Department="disabled"){
document.form1.Department.disabled=true;
}
}

Kakao
05-02-2006, 11:14 PM
It seems so obvious that I must be missing something. What happens if you try this?


function enableQ1(){
if (Department="disabled"){
document.form1.Department.disabled=false;
}
else document.form1.Department.disabled=true;
}

h8ids
05-02-2006, 11:29 PM
I've tried that; didn't work.
The field becomes active but will not de-activate when a user pushes the button again.

Kakao
05-02-2006, 11:40 PM
Do you need the Department variable? What if you just negate the disabled condition?

function enableQ1(){
document.form1.Department.disabled = !document.form1.Department.disabled;
}

h8ids
05-03-2006, 03:14 PM
Kakao,

That's got it.

Thank you

Beagle
05-03-2006, 10:34 PM
Just to explain what happened here:

you were using the assignment operator and not the comparison operator:

Department="disabled" vs Department=="disabled"

because of this, Department was always "disabled", hence your behavior.

6arredja
05-03-2006, 11:02 PM
good call beagle

i noticed that too just now

ive made this mistake a few times as well



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum