Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 26th, 2003, 09:10 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynamic dropdown boxes

hello,

the logic behind the code i post is as follows:

the user selects a studentid from the dropdown box and the second dropdown box automatically displays the corresponding student name.

i need to post the data in the dropdown boxes to another database. i am ok with that just that there's a wrong posting taking place.

the code posts the same drop down value to two fields - studentid field gets the studentid value and the studentname field also gets the studentid value. if you look well in the code you will see why it is doing that. i have not yet managed to find a solution to this probelm and so i am asking for help.

<%
Dim conn
Dim rs
Dim strconn

Session("DataConn_ConnectionString") = _
"DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=letmein; DBQ=" & Server.MapPath("\db.mdb")
strconn = Session("DataConn_ConnectionString")
set conn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
conn.open strconn
strsql = "SELECT StudentId, StudentName FROM students"
rs.open strsql, conn, 2, 2

Response.Write "<SELECT name=studentid onchange=""studentname.value = this.value;"">"
While not rs.EOF
Response.Write "<OPTION value=" & rs("studentid") & ">" & rs("studentid") & "</OPTION>"
rs.MoveNext
Wend
Response.Write "</SELECT>"
rs.MoveFirst
Response.Write "<SELECT name=studentname onchange=""studentid.value = this.value;"">"
While not rs.EOF
Response.Write "<OPTION value=" & rs("studentid") & ">" & rs("studentname") & "</OPTION>"
rs.MoveNext
Wend
Response.Write "</SELECT>"
%>

is there a way whereby i could solve this problem? studentid dropdown box posts to studentid field and studentname posts to studentname field.

i would appreciate your help.

fmh002
Reply With Quote
  #2 (permalink)  
Old June 26th, 2003, 08:35 PM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Firstly,
Is it imperative that you hold the student name in the second table. the whole point of relational database is to avoid that kind of thing. If you know the id you can find the name from the students table.
OR
Puting that aside you can populate the field straight from the database when you do your insert. Using the second dropdown for display only.
strsql = "Insert into newTable select studentID, studentName from students where studentId = " & request("studentID")
OR
If you really want to do it in code you use the selected index property of the dropdown boxes. Again set the value of the studentname dropdown to studentname instead of id. The onchange event will set the index value of the one box to the index value of the the otherbox
Take note of the new onchange events.
eg

Response.Write "<SELECT name=studentid onchange=""studentname.options(studentid.selectedI ndex).selected='true';"">"
While not rs.EOF
Response.Write "<OPTION value=" & rs("studentid") & ">" & rs("studentid") & "</OPTION>"
rs.MoveNext
Wend
Response.Write "</SELECT>"
rs.MoveFirst
Response.Write "<SELECT name=studentname onchange=""studentid.options(studentname.selectedI ndex).selected='true';"">"
While not rs.EOF
Response.Write "<OPTION value=" & rs("studentname") & ">" & rs("studentname") & "</OPTION>"
rs.MoveNext
Wend
Response.Write "</SELECT>"

This is possible because you are using the same recordset to poputale both boxes so the ids and names will be in the same order and have the same index.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Menus - Using multiple dropdown boxes Sebastiaan ASP.NET 1.0 and 1.1 Basics 1 April 18th, 2007 06:25 AM
Dynamic Menu - Using multiple dropdown boxes Sebastiaan Javascript How-To 2 December 1st, 2003 05:36 AM
Dynamic Menu - Using multiple dropdown boxes Sebastiaan Classic ASP Basics 3 June 7th, 2003 06:38 AM



All times are GMT -4. The time now is 04:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.