Mixing javascript

G

groupie

Hi,
This code is in <head>. If I write this:

<script language="JavaScript" type="text/javascript">
<%
if (oRs.BOF && oRs.EOF )
%>
alert("hello");
</script>
....then the BOF/EOF methods are valid but the IF statement is not.


If I write this instead:
<script language="JavaScript" type="text/javascript">
if (oRs.BOF && oRs.EOF )
alert("hello");
</script>
....then the IF statement is valid but the BOF/EOF methods are not.

How can I fix this please? Thanks.
 
J

Joost Diepenmaat

groupie said:
Hi,
This code is in <head>. If I write this:

<script language="JavaScript" type="text/javascript">
<%
if (oRs.BOF && oRs.EOF )
%>
alert("hello");
</script>
...then the BOF/EOF methods are valid but the IF statement is not.


If I write this instead:
<script language="JavaScript" type="text/javascript">
if (oRs.BOF && oRs.EOF )
alert("hello");
</script>
...then the IF statement is valid but the BOF/EOF methods are not.

How can I fix this please? Thanks.

You did notice the <% ... %> construct, right? Everything within those
"tags" is run on the server side, everything without is run on the
client.

I'm going to blindly assume that the if (..) statement is in fact Java,
and your question is off topic. But anyway:

<%
if (oRs.BOF && oRs.EOF ) {
%><%=
alert("hello");
%><% } %>

Joost.
 
E

Evertjan.

Joost Diepenmaat wrote on 02 feb 2008 in comp.lang.javascript:
I'm going to blindly assume that the if (..) statement is in fact Java,
and your question is off topic. But anyway:

<%
if (oRs.BOF && oRs.EOF ) {
%><%=
alert("hello");
%><% } %>

Wrong, there is no alert() in serverside scripting.

This is fine, however:

<% ' ASP-jscript expected as set higher up
if (oRs.BOF && oRs.EOF ) {
%>

<script type='text/javascript'>
alert("BOF/EOF both valid on server");
</script>

<%
};
%>
 
J

Joost Diepenmaat

Evertjan. said:
Joost Diepenmaat wrote on 02 feb 2008 in comp.lang.javascript:


Wrong, there is no alert() in serverside scripting.

Oops. Ofcourse.

Joost.
 
G

groupie

Oops. Ofcourse.

Joost.

I didn't know what <% %> actually meant...thanks! I could also use
runat = 'server' ?

I suppose I shouldn't have used 'alert' in my example - my main focus
was the IF statement and BOF/EOF. Valid statements are highlighted in
blue in dreamweaver when they are valid, and the BOF/EOF are
highlighted in pink.
In my examples, I could only have the IF valid and BOF/EOF invalid, or
vice-versa, never both at the same time. I didn't really understand
why the <% %> "tags" made things any different.
 
J

Joost Diepenmaat

groupie said:
I didn't know what <% %> actually meant...thanks! I could also use
runat = 'server' ?

Who knows? You haven't specified *anything* about the server. We're not
sure if it's running Java/JSP, Javascript (like ye olde netscape server)
or something else, let alone what kind of "template" constructs it
provides.
I suppose I shouldn't have used 'alert' in my example - my main focus
was the IF statement and BOF/EOF. Valid statements are highlighted in
blue in dreamweaver when they are valid, and the BOF/EOF are
highlighted in pink.
In my examples, I could only have the IF valid and BOF/EOF invalid, or
vice-versa, never both at the same time. I didn't really understand
why the <% %> "tags" made things any different.

Ask the person who gave you this code to explain.

Joost.
 
E

Evertjan.

groupie wrote on 02 feb 2008 in comp.lang.javascript:
I didn't know what <% %> actually meant...thanks! I could also use
runat = 'server' ?

Whatever!

Under ASP that is not exactly the same.
I suppose I shouldn't have used 'alert' in my example - my main focus
was the IF statement and BOF/EOF. Valid statements are highlighted in
blue in dreamweaver when they are valid, and the BOF/EOF are
highlighted in pink.

Plesant dreams. Uding code you do not understand is always a bad idea, so
stop using dreamweaver and alike till you understand the code it produces,
and do your own coding till that time.
In my examples, I could only have the IF valid and BOF/EOF invalid, or
vice-versa, never both at the same time. I didn't really understand
why the <% %> "tags" made things any different.

Valid?
How can If as a statement be invalid?
A better question is: Does it do wat you want it to do?
 
T

Thomas 'PointedEars' Lahn

groupie said:
This code is in <head>.

Actually, it is not. It is between <head> and </head> *server-side*. It
may be within said:
If I write this:

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

Remove the deprecated `language' attribute, `type' suffices.
<%
if (oRs.BOF && oRs.EOF )
%>
alert("hello");
</script>
...then the BOF/EOF methods are valid but the IF statement is not.

<% ... %> indicates ActiveServer Pages. The default programming language
in ASP is VBScript which syntax naturally differs from JScript (another
programming language that ASP supports).

Either

<%
If oRs.BOF And oRs.EOF
%>
window.alert("hello");
<%
End If
%>

or

<%@ LANGUAGE = "JScript" %>
<%
if (oRs.BOF && oRs.EOF)
{
%>
window.alert("hello");
<%
}
%>

should work (I recommend the latter, even if it means a rewrite). It would
generate

<script type="text/javascript">
window.alert("hello");
</script>

if the condition was met.
If I write this instead:
<script language="JavaScript" type="text/javascript">
if (oRs.BOF && oRs.EOF )
alert("hello");
</script>
...then the IF statement is valid but the BOF/EOF methods are not.

http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1DontWork
http://jibbering.com/faq/#FAQ4_43

`oRs' would be a reference to an object that exists server-side only.
I didn't know what <% %> actually meant...thanks! I could also use
runat = 'server' ?

You could get a minimum clue before you start messing around with
(server-side) programming. There are plenty (online) resources out there,
including several about ASP, with the MSDN Library being not the least one.


PointedEars
 

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

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,373
Latest member
Desiree036

Latest Threads

Top