
February 16th, 2008, 04:02 PM
|
 |
KIS
|
|
Join Date: Jul 2007
Location: USA
|
|
Quote: | Originally Posted by izzzz hi am trying to code a online exam in asp .i need to retrive the value of radio selected by user for mark calculation...plz help me with it.. thanks in advance.. the table has qn,4choices n ans..
Code:
<% Option Explicit
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdTableDirect = &H0200
Const adUseClient = 3
Dim adoCon
Dim rs
Dim strSQL
%>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form name="conduc" method="post">
<%
Set adoCon = Server.CreateObject("ADODB.Connection")
Set rs= Server.CreateObject("ADODB.Recordset")
adoCon.Open "DSN=online_details"
strSQL="SELECT * FROM level1"
if Len(Request("pagenum")) > 0 then
response.write "choice" & Request("choice")
The mark calculation should appear here
end if
rs.PageSize = 1
rs.CacheSize = 1
rs.CursorLocation = adUseClient
rs.open strSQL,adoCon
If Len(Request("pagenum")) = 0 Then
rs.AbsolutePage = 1
Else
If CInt(Request("pagenum")) <= rs.PageCount Then
rs.AbsolutePage = Request("pagenum")
Else
rs.AbsolutePage = 1
End If
End If
Dim abspage, pagecnt
abspage = rs.AbsolutePage
pagecnt = rs.PageCount
If Not rs.EOF Then
response.write rs.Fields("Question")
response.write "<br><input type=radio name=choice value=first>"
response.write rs.Fields("Option1")
response.write "<br><input type=radio name=choice value=second>"
response.write rs.Fields("Option2")
response.write "<br><input type=radio name=choice value=third>"
response.write rs.Fields("Option3")
response.write "<br><input type=radio name=choice value=fourth>"
response.write rs.Fields("Option4")
Response.Write "</form>"
response.write("Select your option,click next to confirm and go to next question")
response.write "" & Request.ServerVariables("SCRIPT_NAME") & "?pagenum=" & abspage + 1 & ""
If abspage < pagecnt Then
Response.Write "<a href=""" & Request.ServerVariables("SCRIPT_NAME") & "?pagenum=" & abspage + 1 & &""">Next </a>"
End If
End If
rs.Close
Set rs = Nothing
%>
</body>
</html>
|
instead of trying to explain the request objects (form(post)/querystring(get) i modified your code with a request.form method vs a link (get)....in a nutshell the link carries the value of pagenum fine...however it does not "post" values from the form like a submit button...either use javascript or a submit button...you can use an input type=image if you do not care for the basic submit button...this tag is a natural submit button despite its name...
also note i used a dsn-less connection and a for loop vs writing out the same pattern ...also...at the end your logic removes the next button...however you'll have figure out the logic for final submission....let us know if you have trouble when you get to that point...the shell is there...modify as needed...good luck
Code:
<% 'Option Explicit %>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form name="conduc" method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<%
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adCmdTableDirect = &H0200
Const adUseClient = 3
Dim adoCon, rs, strSQL,abspage, pagecnt,sFilePath,sConn,iPageNum, sChoice
iPageNum = Request.Form("pagenum")
strSQL="SELECT * FROM level1"
Response.Write "<p>" & Request.Form("choice") & "</p>"
Set adoCon = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.recordset")
sProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
sPath = "Data Source=" & Server.MapPath("db/online_details.mdb") & ";"
adoCon.Open sProvider & sPath
rs.PageSize = 1
rs.CacheSize = 1
rs.CursorLocation = adUseClient
rs.open strSQL,adoCon
If Len(iPageNum) = 0 Then
rs.AbsolutePage = 1
Else
If CInt(iPageNum) <= rs.PageCount Then
rs.AbsolutePage = iPageNum
Else
rs.AbsolutePage = 1
End If
End If
abspage = rs.AbsolutePage
pagecnt = rs.PageCount
If Not rs.EOF Then
Response.Write rs("Question") & "<br>"
For i = 1 to 4
Response.Write _
"<input type=""radio"" name=""choice"" value=""Option_" & i & """>" & rs("Option" & i) & "<br>" & vbcrlf
Next
End If
Response.Write "<p>Select your option, click next to confirm and go to next question</p>"
If abspage < pagecnt Then
Response.Write "<input type=""hidden"" name=""pagenum"" value=""" & abspage + 1 & """>" & vbcrlf & _
"<input type=""image"" src=""http://persianmirror.com/Images/PhotoAlbumButtons/next.jpg"">"
End If
rs.Close
Set rs = Nothing
%>
</form>
</body>
</html>
Last edited by keep_it_simple : February 16th, 2008 at 04:08 PM.
|