SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2005
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    disabling select element

    Hello

    I am trying to disable a couple of form elements if a specific value is entered into another element. it works for text boxes, but i also need to disable upload (input file) elements and select boxes, where it is not working. Here is what i have:

    the toggle function is called from an onchange event in an option element, which is passed to the function.
    Code:
    function toggle(option){
    	if(option.value == 'No'){
    		disableElement(document.getElementById('House Number'));
                    disableElement(document.getElementById('Street'));
                    disableElement(document.getElementById('Picture'));
    	}else{
    		enableElement(document.getElementById('House Number'));
                    //etc
    	}
    }
    
    function disableElement(element){
    	element.disabled = true;
    }
    
    function enableElement(element){
    	element.disabled = false;	
    }
    As i say, this works ok for textboxes, but not select boxes or file upload boxes, which i need to be disabled too. Is the syntax slightly different for these elements?

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2008
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    looks fine. Try removing the spaces in the element with the id "House Number"


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
  •