...

View Full Version : select all items in a list box with a check box or a radio button or a button



akpaga
05-02-2008, 02:33 PM
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

abduraooft
05-02-2008, 03:34 PM
<!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>

akpaga
05-02-2008, 04:31 PM
thank you very much....

phantom007
10-30-2008, 12:44 PM
Herez another solution:




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')">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum