error with variable declaration

K

Kevin

Hi,

My problem is:
when i declare variable 'recuur' in Jscript like it is below, no problem.
But if i declare 'recuur' like: var recuur=<%=recuur%>
then i get two errors:
"totday is not defined" and "syntax error: var recuur=10"

Any idea what's wrong?
Thanks
Kevin



<%
totday=request.cookies("totday") => =14
.....
sql="select range from hr order by range;"
set rs=Server.CreateObject("ADODB.Recordset")
rs.open sql, OBJDC, 3, 3
dim allhr
Set rs = objdc.execute(sql)
if not rs.eof then
allhr = rs.GetRows()
recuur = UBound(allhr, 2) + 1 => =10
end if
....
%>
.....
<script type="text/javascript">
totday=<%=totday%>
recuur=<%=recuur%>
....
 
R

Randy Webb

Kevin said the following on 12/5/2005 3:37 PM:
Hi,

My problem is:
when i declare variable 'recuur' in Jscript like it is below, no problem.
But if i declare 'recuur' like: var recuur=<%=recuur%>
then i get two errors:
"totday is not defined" and "syntax error: var recuur=10"

Any idea what's wrong?

Show the actual code that gets sent to the browser, not the ASP Code
that generates it.
 
K

Kevin

I found it.
I was wrong: '<%=totday%>' had no value because the cookie had the wrong
name.
But what i still don't understand, is why the next line (var
recuur=<%=recuur%>) is considered as an syntax error and not without 'var'.
If i insert ALERT between the two lines like this:
totday=<%=totday%>
alert("ok")
var recuur=<%=recuur%>

i get no error. Strange isn't it?


Randy Webb said:
Kevin said the following on 12/5/2005 3:37 PM:

Show the actual code that gets sent to the browser, not the ASP Code
that generates it.
http://www.JavascriptToolbox.com/bestpractices/
 
P

Patrice

As Randy said, jsut check the JS code created by your ASP pages... Also it
looks like you forgot ; at the end of each line...
--
 
R

Randy Webb

Patrice said the following on 12/6/2005 5:16 AM:
As Randy said, jsut check the JS code created by your ASP pages... Also it
looks like you forgot ; at the end of each line...

The ; at the end of the line is optional and has no bearing on syntax
errors.
 
R

Randy Webb

Kevin said the following on 12/6/2005 3:16 AM:
I found it.
I was wrong: '<%=totday%>' had no value because the cookie had the wrong
name.
But what i still don't understand, is why the next line (var
recuur=<%=recuur%>) is considered as an syntax error and not without 'var'.
If i insert ALERT between the two lines like this:
totday=<%=totday%>
alert("ok")
var recuur=<%=recuur%>

i get no error. Strange isn't it?

It depends on what the server is sending to the browser. You have to
check the code generated by the server (not the server side code) when
trying to debug client-side script issues.
 
B

Bob Barrows [MVP]

Kevin said:
I found it.
I was wrong: '<%=totday%>' had no value because the cookie had the
wrong name.
But what i still don't understand, is why the next line (var
recuur=<%=recuur%>) is considered as an syntax error and not without
'var'. If i insert ALERT between the two lines like this:
totday=<%=totday%>
alert("ok")
var recuur=<%=recuur%>

i get no error. Strange isn't it?

Randy said:
Kevin said the following on 12/6/2005 3:16 AM:

It depends on what the server is sending to the browser. You have to
check the code generated by the server (not the server side code) when
trying to debug client-side script issues.


What Randy means is that you need to load the page into your browser and
click View Source so you can see the final resulting javascript code.

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top