Gossamer Forum
Home : General : Internet Technologies :

Javascript - select all "select" values

Quote Reply
Javascript - select all "select" values
Hi,

I'm trying to make a <select> form object automatically select all of the values in it, when clicking on a link.

For example:

Code:
<p>Categories: [ <a href="#" onclick="CheckAll();">select all</a> ]</p>

<select size="9" name="Categories" multiple>
<option value="5">bar</option>
<option value="2">bla bla bkl </option>
<option value="3">dum de dar da</option>
<option value="6">dghfgd</option>
<option value="4">foo</option>
<option value="1">test</option>
</select>

..and then the CheckAll() function would need to select all of the "options" inside the "select" input.

I have some code I've used before for "check-boxes", so they all get ticked - but this doesn't work for a SELECT field. For reference, here is the code that works with checkbox type elements:

Code:
<script language="Javascript">
function CheckAll (box) {
for (var i = document.editor_add.elements.length - 1; i >= 0; i--) {
document.editor_add.elements[i].checked = true;
}
}
</script>

Any suggestions?

TIA!

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread Javascript - select all "select" values Andy 5845 May 8, 2007, 9:09 AM
Thread Re: [Andy] Javascript - select all "select" values
olivers 5439 Jul 24, 2007, 12:29 AM
Post Re: [olivers] Javascript - select all "select" values
Andy 5450 Jul 24, 2007, 2:24 AM