Click to See Complete Forum and Search --> : clear all selections in a select field


chastings
10-29-2003, 10:13 AM
I have used HTML <Select> tag to create a list of choices.
The list of choices is very lengthy (30) and I would like to insert a button that will clear all selections.
How do I do this?

Here's an example of the html code used:

<SELECT NAME="E_SubjectMatters" MULTIPLE SIZE=5>
<OPTION>Agriculture
<OPTION>Arts and culture
<OPTION>Colleges and universities
<OPTION>Conservation
<OPTION SELECTED>Economic development and trade
<OPTION SELECTED>Education
<OPTION>Energy
<OPTION>Environment
<OPTION SELECTED>Financial institutions
<OPTION>Forestry

the lis goes on, but you get the idea.

gil davis
10-29-2003, 10:47 AM
This ought to work (untested):
<input type="button" onclick="for(var i in this.form.E_SubjectMatters.options){this.form.E_SubjectMatters.options[i].selected=false;}" value="Clear Selections">

chastings
10-29-2003, 02:34 PM
Thanks a lot!

As you can see, I'm a novice at this and I appreciate your help.

I'll try it and let you know if it works.

Thanks again!