Solved

passing parameters using javascript and asp

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Determining if Request.Form is empty 1 47
JQuery Date Time picker not showing 29 129
XML Parsing Classic ASP 5 56
Need to rewrite code for checking if a file exists 3 65
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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