I have a JavaScript function where I would like to reset the number of Selected rows in a Select List. The Select List is inside a table and it is declared as a FORM. I know that the function is called because the first alert is executed, however, the code that accesses the selectedIndex doesn't seem to get executed. I've verified my syntax against examples and I can't figure out why this doesn't work. Hopefully, someone can point out what I'm doing wrong.
The SelectList declaration:
<table>
<tr>
<td>
<FORM name="pnp">
<SELECT MULTIPLE NAME="PGRNAME" size="10" onChange="redirect(this);" >
<%
String val;
if (progname.size() == 0) out.println(blank);
for (Iterator it=progname.iterator(); it.hasNext() {
val = (String)it.next();
if (prognameSel.get(val) != null) out.println("<OPTION selected>"+val+"</OPTION>");
else out.println("<OPTION>"+val+"</OPTION>");
}
%>
</SELECT></FORM></TD>
..........the rest of the table goes here
The function:
function doReset() {
alert("In doReset"); // this alert shows up
var w = document.pnp.PGRNAME.selectedIndex;
alert("selectedIndex " + w);
var selected_text =document.pnp.PGRNAME.options[w].text;
alert("selectedText " + selected_text);
for (var i=0; i < document.pnp.PGRNAME.length; i++) {
alert( document.pnp.PGRNAME.options.text);
}
}
What I really want to do inside this function is to reset all selected rows, ie.
document.pnp.PGRNAME.selectedIndex=-1;
Any help would be greatly appreciated.
The SelectList declaration:
<table>
<tr>
<td>
<FORM name="pnp">
<SELECT MULTIPLE NAME="PGRNAME" size="10" onChange="redirect(this);" >
<%
String val;
if (progname.size() == 0) out.println(blank);
for (Iterator it=progname.iterator(); it.hasNext() {
val = (String)it.next();
if (prognameSel.get(val) != null) out.println("<OPTION selected>"+val+"</OPTION>");
else out.println("<OPTION>"+val+"</OPTION>");
}
%>
</SELECT></FORM></TD>
..........the rest of the table goes here
The function:
function doReset() {
alert("In doReset"); // this alert shows up
var w = document.pnp.PGRNAME.selectedIndex;
alert("selectedIndex " + w);
var selected_text =document.pnp.PGRNAME.options[w].text;
alert("selectedText " + selected_text);
for (var i=0; i < document.pnp.PGRNAME.length; i++) {
alert( document.pnp.PGRNAME.options.text);
}
}
What I really want to do inside this function is to reset all selected rows, ie.
document.pnp.PGRNAME.selectedIndex=-1;
Any help would be greatly appreciated.