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

Thread: 50% working

  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 50% working

    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.

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

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It seems so obvious that I must be missing something. What happens if you try this?
    Code:
    function enableQ1(){
    	if (Department="disabled"){
    		document.form1.Department.disabled=false;
    	}
            else document.form1.Department.disabled=true;
    }

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've tried that; didn't work.
    The field becomes active but will not de-activate when a user pushes the button again.

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you need the Department variable? What if you just negate the disabled condition?
    PHP Code:
    function enableQ1(){
      
    document.form1.Department.disabled = !document.form1.Department.disabled;


  • #5
    Regular Coder
    Join Date
    Jan 2006
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Kakao,

    That's got it.

    Thank you
    Last edited by h8ids; 05-03-2006 at 03:44 PM.

  • #6
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    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.

  • #7
    New Coder
    Join Date
    Nov 2004
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    good call beagle

    i noticed that too just now

    ive made this mistake a few times as well


  •  

    Posting Permissions

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