Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2005, 01:31 AM
okl okl is offline
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default passing js var to asp sql

hi, i trying to call savetime() on window onUnload.
But the sql give me an error.
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in UPDATE statement.

I debug the sql output it gave me blank, nothing shown.

Thanks for the help!

Code:
<html>
<head>
<title>Question 1</title>

<SCRIPT>
var interval = "";
var hr  = <%=objRst("hrs")%>;
var min = <%=objRst("mins")%>;
var sec = <%=objRst("secs")%>;

function startInterval()
{
    interval = window.setInterval("tTimer()",1000);
}

function stopInterval()
{
    window.clearInterval (interval);
    interval="";
}

function savetime()
{
<%
hrLeft = Request.form("Hr")
MinLeft = Request.form("Min")
SecLeft = request.form("Sec")

strSQL = "UPDATE Attempts SET Hrs=" & HrLeft & ",Mins=" & MinLeft & ",Secs=" & SecLeft & " WHERE studentID ='" & Session("StudID") & "' AND Paper = '" & Session("Paper") & "'"
'response.write strsql
'response.end
objConn.Execute (strSQL)
%>
}

function tTimer()
{
    document.timerform.display.value = hr+':'+zeroPad(min)+':'+ zeroPad(sec--);

    if (sec == -1)
    {
        if (min!="00")
        {
          min = min-1;
          sec = 59;
        }
        if (hr!=0)
        {
          hr = hr-1;
          min = 59;
          sec = 59;
        }
        if (hr==0 && min=="00")
        {
           stopInterval();
           alert ("TIME'S UP");
        }
   }
}
function zeroPad(digit)
{
    if (digit>9) {
      return digit;
    }
    return "0" + digit;
}
</SCRIPT>
</head>


<body bgcolor="#CCFFFF" onUnload="saveTime()">
<script>
startInterval();
</script>

  <form name="timerform" method="POST" action="Q1_Calc.asp" onsubmit="return validate()">

<input type="text" name="display" value="" size="10" readonly>
 
Old March 11th, 2005, 05:40 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

The code in the savetime function runs on the server when the page is first loaded. You need to recognise and understand the difference between server side code, between <% %> and client side code, between <script></script>. View the source of the page and look at the savetime function, this is what runs when the unload event fires, i.e. nothing.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing empty parameters to a js function crmpicco Javascript How-To 0 September 20th, 2005 10:16 AM
passing js var to asp sql okl Classic ASP Databases 1 March 11th, 2005 05:01 AM
passing parameter from js to another jsp page. Regornil JSP Basics 1 August 31st, 2004 08:23 AM
passing var from parent to child darkhalf Javascript 6 April 13th, 2004 09:27 PM
Asp Results in var prgaspar Classic ASP Basics 4 August 19th, 2003 07:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.