Solved

passing parameters using javascript and asp

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

615 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