You are here: irt.org | FAQ | JavaScript | Form | Q1334 [ previous next ]
Try:
<form name="myForm"> <select name="mySelect" multiple> <option value="value data 0">text data 0 <option value="value data 1">text data 1 <option value="value data 2">text data 2 <option value="value data 3">text data 3 <option value="value data 4">text data 4 </select> <input type="button" value="Show Selected" onClick="selectAll(this.form.mySelect)"> </form> <script language="JavaScript"><!-- var selects = new Array(); function selectAll(theSel) { if (theSel.selectedIndex > -1) for (var j=0, i=theSel.selectedIndex; i<theSel.options.length;i++) if (theSel.options[i].selected) selects[j++] = theSel.options[i].value; var output = ''; for (var j=0;j<selects.length; j++) output += selects[j] + ' \n'; alert(output); } //--></script>