Advertisement

09.24.2007 at 06:04AM PDT, ID: 22848098
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

ASP: Automatically select value in drop down list based on query string

Asked by LSE_IT_Training in Active Server Pages (ASP)

Tags: , , , ,

We currently have a booking form for IT Training courses. The form pull course information from a database and populates the drop down list with course titles, times, etc.

We would like to increase the functionality of the form so that when a course is selected from the drop down list, the course prerequisites are displayed beneath the drop down list. We also want the selected option in the drop down list to remain selected

Using the code below, i can get the prerequisites text to appear below the drop down but can't get the selected option to remain selected in the drop down. When the page reloads, the drop down reverts to the first option ('Please select a course...' option)

I have tried to do this by comparing the value in the query string to the value on the drop down as the drop down list is generated, marking the option that matches as 'selected' but this isn't working.

How can I get the drop down to retain the selected option when the page reloads?

Thanks!

<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit

'create database connection object
dim ObjConn
set ObjConn = Server.CreateObject("ADODB.Connection")
ObjConn.Open "DSN=students"

session.lcid=2057

'retrieve value of querystring in url
dim strURLID  
strURLID = Request.QueryString("CourseID")
      if IsEmpty(strURLID) then
            strURLID = "0"
      end if

'create recordset to hold upcoming course details for form drop-down
dim rsCourses
Set rsCourses = Server.CreateObject("ADODB.recordset")
rsCourses.ActiveConnection = ObjConn
rsCourses.open "SELECT [TESTCourse details].CourseID, [TESTCourse details].CourseTitleID, [Courses Title].CourseTitle, " &_
"[TESTCourse details].CourseDate, [TESTCourse details].CourseTime " &_
"FROM [Courses Title] INNER JOIN [TESTCourse details] ON [Courses Title].CourseTitleID = [TESTCourse details].CourseTitleID " &_
"WHERE (([TESTCourse details].CourseDate)>Now()) " &_
"ORDER BY [TESTCourse details].CourseDate;"



'create recordset to hold course prereq details

dim rsPrereq
Set rsPrereq = Server.CreateObject("ADODB.recordset")
rsPrereq.ActiveConnection = ObjConn
rsPrereq.open "SELECT [TESTCourse details].CourseTitleID, [TESTCourse details].CourseID, [TESTCourses Title].RemoveCourse, [TESTCourses Title].CourseRequirements" &_
" FROM [TESTCourse details] INNER JOIN [TESTCourses Title] ON [TESTCourse details].CourseTitleID = [TESTCourses Title].CourseTitleID" &_
" WHERE ((([TESTCourses Title].RemoveCourse)=0));"

rsPrereq.Filter = "CourseID ='" & strURLID & "'"
%>

<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta http-equiv="Content-Language" content="en-gb">
<meta name="Description" content="Booking Form for Student Training Tutorials">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="Keywords" content="Training, IT Training, Student Training, Booking Form">
<meta name="ProgId" content="FrontPage.Editor.Document">
<TITLE>IT Training: Student Training Tutorials Booking Form</TITLE>
<link rel="stylesheet" type="text/css" href="../../css/itservices.css">


<script language="javascript">

function checkWholeForm() {

---javascript form validation here---

</script>
</HEAD>

<BODY BACKGROUND="../images/images/its_tile.gif" BGCOLOR="#4A0194" TEXT="#000000" link="#4A0194" vlink="#808080" alink="#808080" topmargin="0" style="font-family: Arial; font-size: 10pt">

----html page header info here---
                 
                 
                 
<form method="POST" action="bookingConfirmationTEST.asp"   name="StudentBookingForm" id="StudentBookingForm">
   
      <p><b><font size="2">1. Which course do you want to book a place on?&nbsp;</font><nobr><font size="2">
      <br>
      <br>
      </font>
                  </nobr></b><nobr><font size="2">
      </font><select NAME="CourseID" SIZE="1" onchange="document.location='bookingTEST.asp?CourseID='+this.options[this.selectedIndex].value;">
      
      <option  value="0" >Please select...</option>
      <%
      
      'loop through recordset to populate the drop down
      Do While Not rsCourses.EOF
            if rsCourses("CourseID") = strURLID then
                        
                        Response.Write ("<option VALUE='" & rsCourses("CourseID") & "' selected>" & rsCourses("CourseTitle") &" - " & rsCourses("CourseDate") & " " & rsCourses("CourseTime") & "</option>")
                        
            else
                        Response.Write ("<option VALUE='" & rsCourses("CourseID") & "'>" & rsCourses("CourseTitle") &" - " & rsCourses("CourseDate") & " " & rsCourses("CourseTime") & "</option>")
            end if

            
      
            rsCourses.MoveNext
      Loop
      rsCourses.close
      set rsCourses = nothing
      %></select>
      </nobr></p>
      <p><font size="2"><b>Course prerequisites:</b> <% if (strURLID <> 0) then response.write rsPreReq("CourseRequirements") %></font></p>

----rest of form here----

<td width="50%"><input type="button" value="Submit" name="B1" onClick="checkWholeForm(this)"></td>
            </tr>
      </table>
</form>

Start Free Trial
 
Loading Advertisement...
 
[+][-]09.24.2007 at 07:38AM PDT, ID: 19948694

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Active Server Pages (ASP)
Tags: down, drop, asp, list, value
Sign Up Now!
Solution Provided By: third
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628