ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Dell PowerEdge Servers
  #1  
Old June 25th, 2003, 01:32 PM
fmh002 fmh002 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 38 fmh002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m
Reputation Power: 5
dropdown boxes posting to the same field

hello,
i managed to get what i wanted from the code below. however i face another problem. 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  
Old June 26th, 2003, 09:25 AM
mohecan mohecan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Melbourne, Australia
Posts: 212 mohecan User rank is Private First Class (20 - 50 Reputation Level)mohecan User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
A select box posts the value record in the option's value.
i.e.
Code:
<select name="example1">
   <option value=1>One</option>
</select>

<select name="example2">
   <option value="One">One</option>
</select>

In example 1 the option "One" - the number 1 will be posted when you use Request.Form("example"), in example 2, option "One" - the word "One" will be posted when you use Request.Form("example")

How to get around it, well try something like the following before your insert command, you need to get the student name before running the update.
Code:
Dim strQStudents, rsStuName
strQStudents = "SELECT StudentID, StudentName FROM students WHERE StudentID=" & Request.Form("studentname")
'remember Request.Form("studentname") has a studentid as the value submitted

'This will return your student name for the id entered.
set rsStuName = conn.execute(strQStudents)

'In your insert query, when you put the student name bit in, put as rsStuName("StudentName")


Hope this helps.
__________________
How can I soar like an eagle when
I'm flying with turkey's?

Reply With Quote
  #3  
Old June 26th, 2003, 12:12 PM
fmh002 fmh002 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 38 fmh002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m
Reputation Power: 5
man i am unable to fit in your code into my add.asp page... i tried the following, could you please check where my mistake is?

the form page: (working fine)

<html>

<head>
<title>New Page 1</title>
</head>

<%
Dim conn
Dim rs
Dim strconn

Session("DataConn_ConnectionString") = _
"DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=letmein; DBQ=" & Server.MapPath("db1.mdb")
strconn = Session("DataConn_ConnectionString")
set conn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
conn.open strconn
strsql = "SELECT STUDENT_ID, STUDENT_NAME FROM STUDENT"
rs.open strsql, conn, 2, 2
%>
<body>

<form method="post" action= "add.asp">

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

rs.MoveFirst

Response.Write "<SELECT name=studname onchange=""studentid.value = this.value;studentname.value = this.value"">"
While not rs.EOF
Response.Write "<OPTION value=" & rs("STUDENT_ID") & ">" & rs("STUDENT_NAME") & "</OPTION>"
rs.MoveNext
Wend
Response.Write "</SELECT>"
%>
<input type=submit value=submit>
</form>
</body>
<%
rs.close
conn.close
set rs = nothing
set conn = nothing
%>
</html>

========================================

the add.asp page (probelms here)

<%
Dim conn
Dim rsAddStudent
Dim strSQL
Dim strQStudents, rsStuName
abc=Request.Form("studname")

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)};uid=;pwd=letmein; DBQ=" & Server.MapPath("db1.mdb")
Set rsAddStudent = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT studs.studentid, studs.studentname FROM studs;"

strQStudents = "SELECT Student_ID, Student_Name FROM Student WHERE Student_ID= '%" & abc & "%'"
set rsStuName = conn.execute(strQStudents)

rsAddStudent.CursorType = 2
rsAddStudent.LockType = 3

rsAddStudent.Open strSQL, conn

rsAddStudent.AddNew
rsAddStudent.Fields("studentid") = Request.Form("studentid")
rsAddStudent.Fields("studentname") = rsStuName
rsAddStudent.Update

rsAddStudent.Close

Set rsAddStudent = Nothing
Set conn = Nothing
Response.Redirect "student.asp"
%>

Reply With Quote
  #4  
Old June 26th, 2003, 06:31 PM
mohecan mohecan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Melbourne, Australia
Posts: 212 mohecan User rank is Private First Class (20 - 50 Reputation Level)mohecan User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Quote:
rsAddStudent.AddNew
rsAddStudent.Fields("studentid") = Request.Form("studentid")
rsAddStudent.Fields("studentname") = rsStuName ("Student_Name")
rsAddStudent.Update


My change is in bold

Also looking at your strQStudName, remove the % marks from the query, you want the record that is equal to the id entered, not those that are like it.

Last edited by mohecan : June 26th, 2003 at 06:34 PM.

Reply With Quote
  #5  
Old June 27th, 2003, 06:27 AM
fmh002 fmh002 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 38 fmh002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m
Reputation Power: 5
mohecan you're my man!

thnx it's posting the student name as well now.

peace

fmh002

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > dropdown boxes posting to the same field


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway