View Single Post
  #1 (permalink)  
Old June 6th, 2017, 08:39 AM
jennypretty jennypretty is offline
Authorized User
Points: 76, Level: 1
Points: 76, Level: 1 Points: 76, Level: 1 Points: 76, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Select/Option/Value on change using Classic ASP

Hello friends,


I tried to create a select option value on change using classic ASP but it didn't work. No error but when I view, nothing pop up from second select.
I like to select student name from first select box, if it matches, then second box shows course name, and third box shows Semester.
I like to store student names and StudentID into DB.
Can anyone help?

Students table
StudentID Firstname Lastname
-------------------------------
01 AAA LN1
02 BBB LN2
03 CCC LN3

Class table
Course CourseID StudentID Semester
-------------------------------------
History C01 01 Spring
History C01 01 Summer
Math C02 02 Spring
Math C02 02 Fall

Code:
         

 <%          Set oRs = Server.CreateObject("adodb.recordset")                             strSQL = " SELECT StudentID, Firstname, Lastname FROM Students Where StudentID = '" & Request.ServerVariables("LOGON_Student") & "'"                             oRs.Open strSQL, myConn                             sName = oRs("Lastname") & ", " & oRs("Firstname")                             if not oRs.eof then %>                                             <select name="Students" id="selectStudent" onChange="this.form.action='default.asp';this.form.submit();">             <option value="<%= oRs(0) %>" <% if trim(request.Form("Students")) = trim(oRs(0)) then response.write " selected "end if %>><%= sName %></option>             <option value="<%= oRs("StudentID") %>" hidden></option>                                             </select>                             <%          end if             %>              <%          if request.Form("Students") <> "" then                             strSQL = " SELECT Course FROM Class WHERE StudentID = '" & request.Form("StudentID") & "'"                             Set oRs = Server.CreateObject("adodb.RecordSet")                             oRs.Open strSQL, myConn                             if not oRs.eof then %>                                             <select name="Class" id="selectClass" onChange="this.form.action='default.asp';this.form.submit();">                                                             <% do until oRs.eof  %>                                                                             <option value="<%= oRs(0) %>" <% if trim(request.Form("Class")) = trim(oRs(0)) then response.write " selected "end if %>><%= oRs(0) %></option>                                                             <% oRs.MoveNext                                                                             loop       %>                                             </select>                             <% end if                             end if             %>             <%          if request.Form("Class") <> "" then                             strSQL = " SELECT Semester FROM Class WHERE Course = '" & request.Form("Course") & "'"                             Set oRs = Server.CreateObject("adodb.RecordSet")                             oRs.Open strSQL, myConn                             if not oRs.eof then %>                                             <select name="Class" id="selectClass" onChange="this.form.action='default.asp';this.form.submit();">                                                             <% do until oRs.eof  %>                                                                             <option value="<%= oRs(0) %>" <% if trim(request.Form("Class")) = trim(oRs(0)) then response.write " selected "end if %>><%= oRs(0) %></option>                                                             <% oRs.MoveNext                                                                             loop       %>                                             </select>                             <% end if                             end if             %>

Last edited by jennypretty; June 6th, 2017 at 08:44 AM.. Reason: enter code
Reply With Quote