User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 456,515 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,726 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 1158 | Replies: 2
Reply
Join Date: Sep 2007
Posts: 7
Reputation: eng.nema is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
eng.nema eng.nema is offline Offline
Newbie Poster

Question ASP electronic exam project, problem when update data base

  #1  
Sep 24th, 2007
hellow

i have problem with my exam project
i program it in asp , and i have javascript function and this function should return the value of raduo button checked
and i then use this value in ASP code
the problem is that function return null or undifined


i try to send the file exam.asp but i can't so i paste the code here please coppy it and try to see where the error
also i attache the file as text file


<!--#include file="Connection.asp"-->

<html dir="rtl">
<head>


<script language = "JavaScript">

function getRadioValue(radioObject) {
for (var i=0; i<radioObject.length; i++) {
if (radioObject[i].checked) {
var answer = radioObject[i].value;
break ;
}
}
return answer
}

</script>
<title> Electronic Computer Network Exam </title>
</head>

<body >
<p align="center"><i><b><font color="#432896" size="6" face="Comic Sans MS">Computer Network Exam </font></b></i></p>

<table dir= rtl border="0" width="100%" id="table1">

<%
if request("do")="next" then
i=request("i")
i=i+1


elseif request("do")="pervious" then
i=request("i")
i=i-1


else
i=2
end if


selectSQL="select * from question "

Dim oRecordset
Set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3 'adUseClientrs.CursorLocation = 3 ' adUseClient
rs.pagesize=1

rs.open selectSQL,ado

if cint(i)>rs.pagecount+1 then
'update_Answer()
response.write "end of questions.............." & rs.pagecount &"?"
response.redirect("result.asp")
end if
rs.AbsolutePage=i-1

if cint(i)<2 then

response.redirect ("exam2.asp")
end if
if NOT rs.EOF then
%>
<tr>
<td align="left" height="19"><p>
<font color="#800000" face="Times New Roman"><%=rs.FIELDS("Question").VALUE%> </font> </td>
<td width="67" height="19"><font color="#800000"><b> <font face="Times New Roman"><%=rs.FIELDS("Q_ID").VALUE%></font>
<INPUT type=hidden value=<%=rs.FIELDS("Q_ID").VALUE%> name="m"></b> </font>
<font face="Times New Roman"> <b><font color="#800000">&nbsp;Q</font></b></font></td>
</tr>


<form method="get" name="answer_form">
<tr>

<td align="left"><font face="Times New Roman"><%=rs.FIELDS("a").VALUE%></font></td>
<td width="67"><font color="#000080" face="Times New Roman">
<INPUT type="radio" value="1" name="R1" style="font-weight: 700"><b>a</b></font> </td>
</tr>


<tr>
<td align="left"><font face="Times New Roman"><%=rs.FIELDS("b").VALUE%></font></td>
<td width="67"><font color="#000080" face="Times New Roman">
<INPUT type="radio" value="2" name="R1" style="font-weight: 700"><b>b</b></font></td>
</tr>


<tr>
<td align="left"><font face="Times New Roman"><%=rs.FIELDS("c").VALUE%></font></td>
<td width="67"><font color="#000080" face="Times New Roman">
<INPUT type="radio" value="3" name="R1" style="font-weight: 700"><b>c</b></font></td>
</tr>


<tr>
<td align="left"><font face="Times New Roman"><%=rs.FIELDS("d").VALUE%></font></td>
<td width="67"><font color="#000080" face="Times New Roman">
<INPUT type="radio" value="4" name="R1" style="font-weight: 700"><b>d</b></font></td>
</tr>

</form >
<script LANGUAGE="JavaScript"><!--BEGIN HIDING
radio=getRadioValue(answer_form.R1)
alert(getRadioValue(answer_form.R1))
//END HIDING-->
</SCRIPT>

<form>
<tr>
<td>
<p align="left">
<input type="checkbox" name="MyCheck<%=i%>" value="<%=rs.FIELDS("Q_ID").VALUE%>" style="float: left">mark</p>
</td>
</tr>
<input type="hidden" name="counter" value="<%=i%>">

<%
update_Answer()
%>
</form>

<%
if request("do")="review" then
response.redirect("review.asp")
end if
%>

<%
if request("do")="end" then
response.redirect ("result.asp")
end if
%>

<%
end if
%>
</table>

<TABLE id=table2 style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-COLLAPSE: collapse; BORDER-RIGHT-WIDTH: 0px" borderColor=#111111 height=1 cellSpacing=0 cellPadding=0 width=749 align=left border=1>
<TBODY>
<TR>



<TD style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none" align=middle width=97 height=1>
<FORM method=POST action="?do=next" >
<INPUT type=hidden value=<%=i%> name="i">
<P align=center>&nbsp;&nbsp; <INPUT style="FONT-SIZE: 14pt; FLOAT: right" type=submit value=" NEXT" name=NEXT ></P>
</FORM>
</TD>

<TD style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none" align=middle width=154 height=1>
<form method="POST" action="?do=pervious">
<INPUT type=hidden value=<%=i%> name="i"> &nbsp;
<INPUT style="FONT-SIZE: 14pt; FLOAT: right" type=submit value=PERVIOUS name=PERVIOUS>
</form>
</TD>

<TD style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none" align=middle width=103 height=1>
<form method="POST" action="?do=review"> &nbsp;
<input type="submit" value="Review" name="Review" style="font-size: 14pt; float:right">
</form>
</TD>

<TD style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none" align=middle width=219 height=1>
<FORM method=POST action="?do=end"><P>&nbsp;
<INPUT style="FONT-SIZE: 14pt; FLOAT: left" type=submit value="END " name="END "></P>
</FORM>
</TD>

</TR>
</TBODY>
<% update_Answer()%>

</TABLE>
<%
Sub update_Answer()
r=request("radio")

'Initialise the strSQL variable with an SQL statement to query the database

strSQL = "SELECT answer.* FROM answer WHERE Q_ID="&(rs.FIELDS("Q_ID").VALUE-1)
'Reset server objects
rs.Close
Set rs = Nothing
Set rs = Server.CreateObject("ADODB.Recordset")

'Set the cursor type we are using so we can navigate through the recordset
rs.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rs.LockType = 3

'Open the recordset with the SQL query
rs.Open strSQL, ado

'Update the record in the recordset

rs.Fields("user_answer")=cint®
'Write the updated recordset to the database
rs.Update
'Reset server objects
rs.Close
Set rs = Nothing
Set adoCon = Nothing
End Sub
%>
</body>
</html>


please help me if you can

thanks
Attached Files
File Type: txt exam.txt (6.7 KB, 3 views)
File Type: txt Connection.txt (495 Bytes, 2 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 145
Reputation: hopalongcassidy is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 13
hopalongcassidy's Avatar
hopalongcassidy hopalongcassidy is offline Offline
Junior Poster

Re: ASP electronic exam project, problem when update data base

  #2  
Oct 8th, 2007
I'm not going to study your code in detail, but I did look at the getRadioValue function.

The one thing that occurred to me was that if no radio element had been checked (which is quite often the case when a form is first loaded), then the "var answer = radioObject[i].value;" statement would not have been executed. Thus, the "answer" variable would not have been defined.

Is it possible that this caused your error?

Hoppy
Reply With Quote  
Join Date: Sep 2007
Posts: 7
Reputation: eng.nema is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
eng.nema eng.nema is offline Offline
Newbie Poster

Re: ASP electronic exam project, problem when update data base

  #3  
Oct 11th, 2007
Thank you very much ; hopalongcassidy
you are right and my problem solved

Thank you again
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP Forum

All times are GMT -4. The time now is 3:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC