SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard westmich's Avatar
    Join Date
    Mar 2000
    Location
    Muskegon, MI
    Posts
    2,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Using Checkbox to Enable/Disable Input

    I don't know why I struggle so much with javascript, but I can never seem to get through it. I've read through my previous posts and took the lessons learned, but yet I still struggle to find why this isn't working!

    Code:
    <form name="MyForm" action="test.cfm" method="post">
    	<input type="file" name="MyFile" size="30" id="MyFile"><br>
    	<input type="checkbox" name="chkMyFile" onclick="ToggleEnableDisable(document.MyForm.MyFile)">
    </form>
    <script>
    	// toggle disabled option
    	function ToggleEnableDisable(element){
    		var Element2Toggle = element.getAttribute('Disabled');
    		if(Element2Toggle == true){
    			document.element.disabled = false;
    		}else{
    			document.element.disabled = true;
    		}
    	}
    </script>
    Westmich
    Smart Web Solutions for Smart Clients
    http://www.mindscapecreative.com

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Try this:
    Code:
    <form name="MyForm" action="test.cfm" method="post">
    	<input type="file" name="MyFile" size="30" id="MyFile"><br>
    	<input type="checkbox" name="chkMyFile" onclick="ToggleEnableDisable(document.forms["MyForm"].elements["MyFile"])">
    </form>
    <script>
    	// toggle disabled option
    	function ToggleEnableDisable(element){
    		var Element2Toggle = element.disabled;
    		if(Element2Toggle){
    			element.disabled = false;
    		}else{
    			element.disabled = true;
    		}
    	}
    </script>


Bookmarks

Posting Permissions

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