|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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? |
|
#3
|
|||
|
|||
|
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" %> |
|
#4
|
|||
|
|||
|
Quote:
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. |
|
#5
|
|||
|
|||
|
mohecan you're my man!
thnx it's posting the student name as well now. peace fmh002 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > dropdown boxes posting to the same field |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|