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
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    select all items in a list box with a check box or a radio button or a button

    i have a select box that gets populated from a table in the database.
    it contains names of the customers.
    i want a check box or a radio button which when checked selects all the items (names) in the select box.

    thanks in advance

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    	"http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    	<meta http-equiv="Content-type" content="text/html; charset=utf-8">
    	<title> select all</title>
    	
    	
    	<script type="text/javascript" charset="utf-8">
    		function selectAll(chkObj){
    			var multi=document.getElementById('multi');
    			if(chkObj.checked)
    				for(i=0;i<multi.options.length;i++)
    				multi.options[i].selected=true;
    			else
    				for(i=0;i<multi.options.length;i++)
    				multi.options[i].selected=false;
    				
    			
    		}
    	</script>
    	
    </head>
    
    <body>
    	
    	<select size="5" multiple="multiple" id="multi" name="multi">
    	<option value="val0">sea zero</option>
    	<option value="val1">sea one</option>
    	<option value="val2">sea two</option>
    	<option value="val3">sea three</option>
    	<option value="val4">sea four</option>
    </select>
    <input type="checkbox" onclick="selectAll(this);"/>
    </body>
    </html>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you very much....

  • #4
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Thumbs up

    Herez another solution:


    Code:
    		function selectAllOptions(id)
    	{
    	var ref = document.getElementById(id);
    	
    	for(i=0; i<ref.options.length; i++)
    	ref.options[i].selected = true;
    	}
    <select id="aaa" size="15" multiple="multiple">
    <option>Orange</option>
    <option>Banana</option>
    <option>Apple</option>
    <option>Guava</option>
    </select>

    <input type=button onclick="selectAllOptions('aaa')">


  •  

    Posting Permissions

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