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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts

    Looking for a script..

    Hiya,

    I'm wanting a script that will disable 3 drop down boxes unless a check box is ticked.

    Any help appreciated!

    Thanks in advance!

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <html>
    <head>
    <script>
    function enableDisableGroup(flag) {
    	var grp = document.getElementsByName('grp1');
    	for(var i=0; i<=grp.length; i++) {
    		grp[i].disabled = !flag;
    	}
    }
    
    function cbF() {
    	enableDisableGroup(document.getElementById('grpCb').checked);
    }
    
    function loadFnc() {
    	enableDisableGroup(document.getElementById('grpCb').checked);
    }
    </script>
    </head>
    <body onload="loadFnc();">
    Dropdown enabled: <input id="grpCb"	type="checkbox"	onclick="cbF();">
    <br>
    <select	name="grp1">
    	<option>1-1</option>
    	<option>1-2</option>
    	<option>1-3</option>
    </select>
    <select	name="grp1">
    	<option>2-1</option>
    	<option>2-2</option>
    	<option>2-3</option>
    </select>
    <select	name="grp1">
    	<option>3-1</option>
    	<option>3-2</option>
    	<option>3-3</option>
    </select>
    </body>
    </html>
    rm -f /

  • #3
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Note that rm-f's code may cause some problems if you plan to submit the form since all of the select-lists are named the same... You may also want to give each separate id's if you need to make a distinction between them in your code.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,519
    Thanks
    3
    Thanked 507 Times in 494 Posts
    see

    http://www.vicsjavascripts.org.uk/Fo...endium.htm#f40

    there are other disable scripts within FormCompendium if that one does not fit


  •  

    Posting Permissions

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