By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,131 Members | 1,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,131 IT Pros & Developers. It's quick & easy.

Mixing javascript

P: n/a
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.
Feb 1 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 2 '08 #2

P: n/a
groupie wrote:
This code is in <head>.
Actually, it is not. It is between <headand </head*server-side*. It
may be within <headand </headclient-side, too.
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_not...ml#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
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Feb 2 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.