Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

passing parameters using javascript and asp

Posted on 2004-10-16
3
Medium Priority
?
1,136 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 180 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 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