Object required?

G

groupie

I get the following error on an ASP page but I don't understand why :
line 13 is if ( writeSessionCookie ('pans','drizzle'))

The error:
Error Type:
Microsoft JScript runtime (0x800A138F)
Object expected
/lands/testpage.asp, line 13

The code:
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="JavaScript" type="text/javascript" src = "scripts/
cookies.js"></script>
<head>
<title>page for testing stuff</title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
<%
if ( writeSessionCookie ('pans','drizzle'))
document.write("cookie written");
else
document.write("cookie not written");
%>
</script>
</body>
</html>

The function:
function writeSessionCookie (cookieName, cookieValue) {

if (testSessionCookie()) {
document.cookie = escape(cookieName) + "=" + escape(cookieValue) +
"; path=/";
return true;
}
else
return false;
}
 
T

Thomas 'PointedEars' Lahn

groupie said:
I get the following error on an ASP page but I don't understand why :
line 13 is if ( writeSessionCookie ('pans','drizzle'))

The error:
Error Type:
Microsoft JScript runtime (0x800A138F)
Object expected
/lands/testpage.asp, line 13

The code:
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="JavaScript" type="text/javascript" src = "scripts/
cookies.js"></script>

You were recommended to remove the `language' attribute, were you not?
<head>
<title>page for testing stuff</title>
</head>

<body>
<script language="JavaScript" type="text/javascript">

Same here.
<%
if ( writeSessionCookie ('pans','drizzle'))
document.write("cookie written");
else
document.write("cookie not written");
%>
</script>
</body>
</html>

The function:
function writeSessionCookie (cookieName, cookieValue) {

if (testSessionCookie()) {
document.cookie = escape(cookieName) + "=" + escape(cookieValue) +
"; path=/";
return true;
}
else
return false;
}

writeSessionCookie() contained in scripts/cookies.js included via the
`script' element is declared *client-side* as document.write() works only
client-side. Everything inside <% ... %> is executed *server-side*. IOW,
neither method is just not there when you call it. Hence the error message.

This is the second time you demonstrate a complete lack of understanding for
client-side and server-side scripting. You should finally learn the basics
and the basic difference between the two before you continue this
half-knowledged messing around.


PointedEars
 
G

groupie

You were recommended to remove the `language' attribute, were you not?



Same here.








writeSessionCookie() contained in scripts/cookies.js included via the
`script' element is declared *client-side* as document.write() works only
client-side.  Everything inside <% ... %> is executed *server-side*.  IOW,
neither method is just not there when you call it.  Hence the error message.

This is the second time you demonstrate a complete lack of understanding for
client-side and server-side scripting.  You should finally learn the basics
and the basic difference between the two before you continue this
half-knowledged messing around.

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16- Hide quoted text -

- Show quoted text -

Slowly learning...
So I know now that ASP renders the page BEFORE Javascript.
In that case in the sample below, is it possible to use session cookie
values (read on client side) (email and pword) to select from a table
(server side sql) (the example uses Request() set in previous page:
looking to replace them with the variables).

<script type="text/javascript">
var email = getCookieValue('email'); //already set in previous page
var pword = getCookieValue('pword'); //already set in previous page
</script>

<%
var strSql;
if ((Request("email") != "") && (Request("pword") != "")) {
strSql = "SELECT email, pword FROM logintable where email = '" +
Request("email") +
"' and pword = '" + Request("pword") + "';";

// more code....
%>
 
S

Stevo

Thomas said:
You were recommended to remove the `language' attribute, were you not?

Yeah groupie, you should be aware that language="javascript" is the
cause of more problems in javascript than anything else. Almost every
problem I've ever seen resolved was fixed by this being removed. We
should add this as item #1 in the FAQ:

Problem: Anything, Solution: Remove language="javascript" from script.

It's such an annoyance that Safari 3.0, Firefox 3.0 and IE8 have all
decided to throw an exception for any script tag that has
language="javascript" in it. </sarcasm>
 
T

Thomas 'PointedEars' Lahn

groupie said:
writeSessionCookie() contained in scripts/cookies.js included via the
`script' element is declared *client-side* as document.write() works only
client-side. Everything inside <% ... %> is executed *server-side*. IOW,
neither method is just not there when you call it. Hence the error message.

This is the second time you demonstrate a complete lack of understanding for
client-side and server-side scripting. You should finally learn the basics
and the basic difference between the two before you continue this
half-knowledged messing around.
[...]

Slowly learning...

Yes, indeed. I ask you *again* to trim your quotes.
So I know now that ASP renders the page BEFORE Javascript.

Not quite. "ASP" "renders" the "page", including the execution of
the server-side script, before the client-side script is executed.
In that case in the sample below, is it possible to use session cookie
values (read on client side) (email and pword) to select from a table
(server side sql) (the example uses Request() set in previous page:
looking to replace them with the variables).

ISTM you are trying password auto-fill, so it should be the other way
around. First the client makes the request, sending the Cookie header along
with it (a previous Set-Cookie or Set-Cookie2 header, or document.cookie
assignment would have set the cookie). You should then evaluate the header
value in order to generate the proper response body via ASP.

Be advised, though, that storing passwords as-is in session cookies is a bad
idea. Many user agents have built-in features to facilitate password form
auto-fill in which case the password is stored in the user profile using a
strong encoding instead.


PointedEars
 
G

groupie

Yeah groupie, you should be aware that language="javascript" is the
cause of more problems in javascript than anything else. Almost every
problem I've ever seen resolved was fixed by this being removed. We
should add this as item #1 in the FAQ:

Problem: Anything, Solution: Remove language="javascript" from script.

It's such an annoyance that Safari 3.0, Firefox 3.0 and IE8 have all
decided to throw an exception for any script tag that has
language="javascript" in it. </sarcasm>

Stevo, you muppet, learn to read the flow of group discussions as soon
as you take your head out of your ass. That post was from PointedEars.
 
G

groupie

You should then evaluate the header
value in order to generate the proper response body via ASP.

I'm not sure what you mean : I'm reading the values back to use in an
SQL statement (I accept the security implications for now). It's the
syntax of the IF and SQL statements I'm trying to code.

<script type="text/javascript">
var email = getCookieValue('email'); //already set in previous page
var pword = getCookieValue('pword'); //already set in previous page
</script>

<%
var strSql;
//if ((Request("email") != "") && (Request("pword") != "")) {
if ((%>email<% != "") && (%>pword<% != "")) {
strSql = "SELECT email, pword FROM logintable where email = '"
+ email +
"' and pword = '" + pword + "';";

// more code....
%>
 
T

Thomas 'PointedEars' Lahn

groupie said:
Stevo, you muppet, learn to read the flow of group discussions as soon
as you take your head out of your ass. That post was from PointedEars.

This was uncalled for. Stevo's sarcastic comment, however inappropriate in
content, was to my *aside* recommending to remove the `language' attribute,
and so in that sense was appropriate to be posted as a followup like he did.

While that particular recommendation is unlikely to solve your problem, it
was and is good advice nonetheless. Not following it may cause a poster to
be perceived as not being able/willing to follow given advice at all, and so
further dealing with their postings may be deemed a waste of time. Use of
street language as displayed here could then only confirm the correctness of
such an assessment.


Score adjusted

PointedEars
 
V

VK

I'm not sure what you mean

He means that server-side processing instructions and client-side
Javascript statements are two completely different unrelated things.
From previous similar threads I know that this rather simple concept
is extremely hard to comprehend to many PHP and ASP developers: so I
will try to give some more explanations.

Server-side processing instructions - in your case all those <%...%>
thingies - being processed, as their name suggests, on the server
while preparing the page content to be sent to client. At this stage
client-side Javascript doesn't exist yet, because the page is not
parsed yet by browser.
After all server-side processing instructions being accomplished, the
final page content being sent to client. If the page contains
Javascript in it, if Javascript supported by browser, and if this
support is not turned off by user: then browser creates Global context
for your script and trying to execute it. On this stage server-side
processor doesn't exist anymore for Javascript - it is left long time
ago on the server.

P.S. I once was thinking of this puzzling catcha, because I met
several experienced and certified PHP/ASP coders but I had to explain
them this server-side vs. client-side concept nearly on fingers and
color cubes and balls before we could come to any result :)
I guess the main gotcha is that in the source both kind of
instructions are oftenly staying together, so forcing into a fake
assumption "close on the screen - close in the life". Some may have a
better idea.



: I'm reading the values back to use in an
 
S

Stevo

groupie said:
Stevo, you muppet, learn to read the flow of group discussions as soon
as you take your head out of your ass. That post was from PointedEars.

Groupie, you teletubby, you need to learn to recognize sarcasm :)

As Thomas said in his response, I was taking a sarcastic dig at him
telling you something that wasn't relevant. So I played the fake
agreeing with him stance. There should be a sarcastic font we can use in
these groups :)
 
G

groupie

I guess the main gotcha is that in the source both kind of
instructions are oftenly staying together, so forcing into a fake
assumption "close on the screen - close in the life". Some may have a
better idea.

Ah Ok I see. Perhaps your reply could be put into the FAQ? It was very
succint.

If I understand what you're saying then, the (server-side) SQL
statement in the <% %> 'tags' below won't contain the values from the
variables, because the (client-side) <script></script> values haven't
been retrieved yet?

<script type="text/javascript">
var email = getCookieValue('email'); //already set in previous page
var pword = getCookieValue('pword'); //already set in previous page
</script>

<%
var strSql;
//if ((Request("email") != "") && (Request("pword") != "")) {
if ((%>email<% != "") && (%>pword<% != "")) {
strSql = "SELECT email, pword FROM logintable where email = '"
+ email + "' and pword = '" + pword + "';";

// more code....
%>

So is there a way of using values retrieved from a cookie in an SQL
statement then?

Stevo: Ok apologies. Flipped for a minute there </apology> :)
 
V

VK

Ah Ok I see. Perhaps your reply could be put into the FAQ?
It was very succinct.

I though once of a FAQ proposal but the thing is that no one is asking
about it in the way to make some general question. FAQ has "question-
answer" structure, and what question to use? "What is the difference
between server-side and client-side processing?" I never saw such
question on c.l.j. It is always has to be pulled out from OP in order
to help him/her from a completely different original question.
If I understand what you're saying then, the (server-side) SQL
statement in the <% %> 'tags' below won't contain the values from the
variables, because the (client-side) <script></script> values haven't
been retrieved yet?
Right.

So is there a way of using values retrieved from a cookie in an SQL
statement then?

Setting and reading cookie is not an exclusive privilege of
Javascript. Any server can do it (if accepted by client). If there are
cookies for given domain, they are being sent as part of request
header from client to server: no custom Javascript needed, it is done
by browser itself. So in your ASP block server-side you may check for
the presence of cookie and use them in any way you need them. If
cookies are not set yet, you can prepare and set them via the response
header from your server.
 
G

groupie

Setting and reading cookie is not an exclusive privilege of
Javascript. Any server can do it (if accepted by client). If there are
cookies for given domain, they are being sent as part of request
header from client to server: no custom Javascript needed, it is done
by browser itself. So in your ASP block server-side you may check for
the presence of cookie and use them in any way you need them. If
cookies are not set yet, you can prepare and set them via the response
header from your server.

Sorry I don't understand. How would I have to change the code posted
to use the cookie values? I've used Request("email") in the SQL which
works (the value is passed from previously SUBMITed page), however I
would like to know how to use the value from the cookie, that was set
in the previous page.

The cookie value is retrieved with the custom javascript function
getCookieValue() which has been included using <script type="text/
javascript" src = "scripts/cookies.js"></script>. Somewhere I need to
call this function, to get the cookie value, to pass into the SQL
statement.

I'm really beginning to hate javascript :-(
 
V

VK

Sorry I don't understand. How would I have to change the code posted
to use the cookie values? I've used Request("email") in the SQL which
works (the value is passed from previously SUBMITed page), however I
would like to know how to use the value from the cookie, that was set
in the previous page.

The cookie value is retrieved with the custom javascript function
getCookieValue() which has been included using <script type="text/
javascript" src = "scripts/cookies.js"></script>. Somewhere I need to
call this function, to get the cookie value, to pass into the SQL
statement.

SQL statement is being executed server-side. At the moment of
executing server-side statements your program already has access to
cookie (if set). If not it can set them by issuing necessary headers
in the response. In ASP it is all handled by Request.Cookies and
Response.Cookies respectively. Client-side scripting is not needed. A
beginners-friendly explanation and samples can be found at
http://www.w3schools.com/asp/asp_cookies.asp
I'm really beginning to hate javascript :-(
For what? For not being able to be executed client-side before
actually being served to client? With the same reason you may hate
your browser then for not being able to display a page before you
actually came to the necessary URL.
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top