Click to See Complete Forum and Search --> : worked in JavaScript


peachy
08-09-2004, 05:37 PM
I know ASP in run at the server and JavaScript on the client but I need help.
I wrote a little program in JavaScript creating a timer to submit a form. But when trying to use it in my ASP it wouldn't work.
**
<script language="JavaScript">
<!--
var theSec=60;
var theMin=1;
var frm="frmTest";
function theTimer()
{
theSec = theSec - 1;
if (theSec == 0){
theMin = theMin - 1;
theSec = 60;
}
if (theMin == 0 && theSec == 1){
frm = document.forms[frm];
frm.submit();
}

window.status="Time remaining is "+theMin+" Minutes "+theSec+" Seconds";
}
setInterval("theTimer()",1000);
//-->
</script>
**
Can it be modified to work with ASP?

Also tried this to print on as ASP but it wouldn't work either:
<form>
<input type="button" value="Print" onClick="window.print();">
</form>

Am I asking for too much?

peachy
08-09-2004, 07:28 PM
Sorry,
Forgot to say the error is:
Microsoft VBScript runtime error '8000a0006'
Overflow

buntine
08-10-2004, 08:49 PM
Because JavaScript runs on the client, it shoud not matter which language you use on the backend. ASP and JavaScript dont even care about each other.

Your not trying to get this to work as an ASP script, are you? Because a server-side language is not cabable of such things.

Regards.

lmf232s
08-11-2004, 02:06 PM
whats wrong with your code. I got it too work fine. I changed two things.

Not sure what you are doing but I put an onload event in the body tag and you were trying to submit a form that did not exist frmTest so I put the name in the <form> tag this is what I have.


<script language="JavaScript">
<!--
var theSec=60;
var theMin=1;
var frm="frmTest";
function theTimer()
{
theSec = theSec - 1;
if (theSec == 0){
theMin = theMin - 1;
theSec = 60;
}
if (theMin == 0 && theSec == 1){
frm = document.forms[frm];
frm.submit();
}

window.status="Time remaining is "+theMin+" Minutes "+theSec+" Seconds";
}
setInterval("theTimer()",1000);
//-->
</script>
**
Can it be modified to work with ASP?
<body onload="theTimer();">
Also tried this to print on as ASP but it wouldn't work either:
<form name=frmTest>
<input type="button" value="Print" onClick="window.print();">
</form>
</body>

peachy
08-12-2004, 11:15 PM
When running on a regular html it does work, but I was trying to find a way to run this on as ASP. I did get the "print" to work.
<form action="admin/logoff.asp" method="post">
<input type="button" value="Print Results" onClick="window.print();">
<input type="submit" value="Exit after Printing">
</form>

I wrote a program to do testing on line and was trying to get a way to submit the test if the applicant didn't complete the test in the alloted time and also have the time counting down on the status bar. (The alloted time was being derived from a database.)

I do understand you can't mix ASP and JavaScript but I was trying to somehow to "have my cake and eat it too" and thought I was just missing something a piece of the puzzle.

Thanks for responding.

buntine
08-12-2004, 11:34 PM
ASP runs from the server. To do this, you would have to reload the page every second!

lmf232s
08-13-2004, 09:35 AM
Peachy,
I am running this as an asp page. Here is some code that I used that includes asp.


<%option explicit%>

<%

Dim MyName, MyDate, Counter

MyName = "This is a test"

MyDate = Date

Counter = Request.Form("Counter")
If Counter = "" then
Counter = 1
end if

%>

<script language="JavaScript">
<!--
var theSec=60;
var theMin=1;
var frm="frmTest";
function theTimer()
{
theSec = theSec - 1;
if (theSec == 0){
theMin = theMin - 1;
theSec = 60;
}
if (theMin == 0 && theSec == 1){
frm = document.forms[frm];
frm.submit();
}

window.status="Time remaining is "+theMin+" Minutes "+theSec+" Seconds";
}
setInterval("theTimer()",1000);
//-->
</script>
**
Can it be modified to work with ASP?
<body onload="theTimer();">
Also tried this to print on as ASP but it wouldn't work either:
<form name=frmTest>
<input type=hidden name=Counter value="<%=Counter%>">
<input type="button" value="Print" onClick="window.print();">
<table>
<tr>
<td>Message:<%=MyName%></td>
</tr>
<tr>
<td>Date:<%=MyDate%></td>
</tr>
<tr>
<td>Counter:<%=Counter%></td>
</tr>
</table>
</form>
</body>


Here i mixed asp in with the html. I can still have javascript and asp on the same page.

I may just be confussed as to what you are asking but, I am running this as a asp page called
JavascriptTimer.asp

Is this not what you want?

Every time this page submits itself counter is increased by 1.

peachy
08-13-2004, 07:13 PM
Go to www.crieffel.com/timer.html this is how I want the timer to work, except in ASP. (watch the timer in the status bar when it expires the page is submitted)

The page will be a series of questions with Radio buttons to select the correct answer. But here is the "kicker". On the example html the status bar starts at 2 minutes but the real site will have up to 70 different tests and each one could have a different time limit so I need to get the "TimeLimit" for the duration of the timer from the database.

I tried the code from the html example on one of the test (ASP) but when the test was submitted the values from the radio buttons was not there. I guess because the page was submitted by JavaScript.

Can I do this by using a loop in VBScript?

I know I keep beating a dead horse but I don't like to be defeated!:(

lmf232s
08-16-2004, 12:04 PM
Peachy,
I am pretty sure that you have all you need to accomplish what you want. I am currently at work but I started a sample online quiz last night to demonstrate a way for you to do it. Not really the way you should do it but just an example showing you that what you want to do is possible.
I almost have it done but i am at work right now and will finish it when i get home tonight.
Later.