Solved

passing parameters using javascript and asp

Posted on 2004-10-16
3
1,103 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now