Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onchange event does not work on select boxes

Status
Not open for further replies.

malaygal

IS-IT--Management
Feb 22, 2006
192
US
I have three dynamic select boxes on my asp page. The Onchange event does not fire off on the first options when selected. I had to go to a different option first and then go to the first option to get around it.

Below is my sample code. Any help will be greatly appreciated.

<SELECT NAME="version" ONCHANGE="document.frmUploadStatus.submit();">
<%
'loop through the recordset...
rs.movefirst
Do Until rs.EOF
'is this a new version?
If rs("version") <> version Then
%>
<OPTION VALUE ="<%=rs("version")%>"><%=rs("version")%></OPTION>
<%
else
%>
<OPTION VALUE = "<%=rs("version")%>" selected><%=rs("version")%></OPTION>
<%
end if
rs.MoveNext
Loop
' finish the version listbox...
rs.close
Set rs = Nothing
%>
 
Thats because the first options are already selected when the page loads, so you haven't changed the value (and thus the onChange doesn't fire). The easiest solution for this is to put an empty option at the top of your select list or an empty value and a "Please Select whatever" option. This way the user is forced to change the box, giving you the onChange event. Using an empty string for a value means you can easily validate that the user has picked an option or left it sitting at the top.

-T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top