SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Aug 2007
    Posts
    494
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disabled select in the form

    Hi all.

    I have this select in the form:

    Code:
    <select size="1" name="CO">
    <option value="">---</option>
    <option value="COAQ">COAQ</option>
    <option value="COCB">COCB</option>
    </select>  
    
    
    <select size="1" name="ZN">
    <option value="">---</option>
    <option value="ZNAQ">ZNAQ</option>
    <option value="ZNCB">ZNCB</option>
    </select>
    I need:

    1) when select value in the select name="CO" disabled all option in the select name="ZN";
    2) when select value in the select name="ZN" disabled all option in the select name="CO";

    Can you help me?
    kind regards
    viki

  2. #2
    SitePoint Enthusiast ZefQ's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    function selected(id) {
    	var select= document.getElementById(id).selectedIndex;   //get witch select has changed
    	var selectValue= document.getElementById(id)[select].value;   //get de value off the selected option
    	var allSelect= new Array();   //create an array for all select elements on the page
    	allSelect= document.getElementsByTagName("select");  //get ell select element
    	if(selectValue) {  //if not empty
    		for(var i=0;i<allSelect.length;i++) {  //loop thru them and disable all select that wasent changed
    			if(allSelect[i].id != id) {
    				allSelect[i].disabled = true;
    			}
    		}
    	}
    	else {  //if the value was empty reenable all select elements again
    		for(var i=0;i<allSelect.length;i++) {
    			allSelect[i].disabled = false;
    		}
    	}
    }

    change from name to id in form

    name="ZO" change to id="ZO"

    and
    <select size="1" name="ZN"> should be <select size="1" name="ZN" onchange="selected()">
    Last edited by ZefQ; Nov 14, 2008 at 12:28.

  3. #3
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    ...


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
  •