Solved

passing parameters using javascript and asp

Posted on 2004-10-16
3
1,120 Views
Last Modified: 2008-01-09
I have a problem can you help me with this

I have questionnaire and all the questions, choices and answers
are from DB.

here's my code:

' this javascript is a timer if it reaches 15 mins, it will automatically
redirect to another page


<script language="JavaScript">
var initVal=15;//// set the timer to 1 minute///
var sec = 0;
function count(){
document.getElementById("divShow").innerHTML=initVal+":"+sec;
var t=setTimeout("count()",1000);
     if (initVal>=0){
          if (sec>0) sec-=1;
          else{
               if (!(initVal==0 && sec==0)){
                    initVal-=1;
                    sec=59;
               }
               else{
                    clearTimeout(t);
                    alert("Your time is up...");
                    window.location.href="reminder.asp";
               }
          }
     }
}
</script>


Set rs = Server.CreateObject("ADODB.Recordset")
sql = "Select * from Question"
rs.Open sql, conn,3,3
if not rs.eof then
do        
code = trim(rs("qcode"))
question = trim(rs("qquest"))
response.write "<input type='Hidden' name="&code&".cdo value="& code &">"
response.write code &". "& question &"<br>"

               Set rs1 = Server.CreateObject("ADODB.Recordset")
               sql = "Select * from Answers where qcode ="& code
               rs1.Open sql, conn,3,3
                    if not rs1.eof then
                    do  
                    qcode = trim(rs1("qcode"))
                       choices = trim(rs1("aansi"))
                   
                    response.write "<input type='radio' name="&qcode&".subcateg value="& choices &">"& choices
                   
               rs1.movenext
               loop until rs1.eof
end if
response.write  "<br><br><br>"
rs.movenext
y = y + 1
loop until rs.eof
end if


if you are going to view this, it would be like this

1. CASH means the same as or opposite of:
()price ()refund ()money ()bank


2. Bill Laird pays a quarter for two cigars. How many can he buy for a dollar?
()2()4()6()8()10


3. The wage paid to an employee:
()G()N()S()V()Y


if the user did not finish the exam and the time limit excedded,
pop up message will be displayed saying "time is up!..."

My question was:
pop up message was displayed because the time limit exceeded.
using javascript, How can i pass the parameters and insert all his answers to db.




thanks in advance.
0
Comment
Question by:liway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
mistyrae earned 45 total points
ID: 12331078
Hi,

You can do this quite easily, although Javascript isn't 100% of the answer... You still should use an ASP page to insert the form data to the database.

In your javascript, when the timeout expires, instead of redirecting the user to a new page, you want to submit your form to the processor page...

<script language="JavaScript">
var initVal=15;//// set the timer to 1 minute///
var sec = 0;
function count(){
document.getElementById("divShow").innerHTML=initVal+":"+sec;
var t=setTimeout("count()",1000);
     if (initVal>=0){
          if (sec>0) sec-=1;
          else{
               if (!(initVal==0 && sec==0)){
                    initVal-=1;
                    sec=59;
               }
               else{
                    clearTimeout(t);
                    alert("Your time is up...");
                    // removed your old redirect code... window.location.href="reminder.asp"; and replaced with //
                    // submit the form (this assumes that the quiz form is the only one on the page
                    document.forms[0].submit();
               }
          }
     }
}
</script>

<form method="post" action="yourformprocessor.asp">
<%
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "Select * from Question"
rs.Open sql, conn,3,3
if not rs.eof then
do        
code = trim(rs("qcode"))
question = trim(rs("qquest"))
response.write "<input type='Hidden' name="&code&".cdo value="& code &">"
response.write code &". "& question &"<br>"

               Set rs1 = Server.CreateObject("ADODB.Recordset")
               sql = "Select * from Answers where qcode ="& code
               rs1.Open sql, conn,3,3
                    if not rs1.eof then
                    do  
                    qcode = trim(rs1("qcode"))
                       choices = trim(rs1("aansi"))
                   
                    response.write "<input type='radio' name="&qcode&".subcateg value="& choices &">"& choices
                   
               rs1.movenext
               loop until rs1.eof
end if
response.write  "<br><br><br>"
rs.movenext
y = y + 1
loop until rs.eof
end if
%>
</form>

- misty
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Questions about INCLUDE FILES 2 47
Save ms data to server side. 19 64
Cannot open file from ASP if user is "logged in" 13 40
VB script help 23 50
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question