what is the difference between <%@ LANGUAGE = VBScript %> and <SCRIPT LANGUAGE="VBScript"> ?

Hi,

what is the difference between <%@ LANGUAGE = VBScript %> and <SCRIPT LANGUAGE="VBScript"> ?

The follows are two parts of codes, the first one works, but the second one doesn't work.

The error information is: "Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'document' ".

 Is there any possibility to make the second one work? Thanks.

The first one:

<HTML>
<HEAD>
<TITLE>Document.Write Examples</TITLE>
</HEAD>
<BODY BGCOLOR=WHITE>
This line is part of the regular body text.
<P>
<SCRIPT LANGUAGE="VBScript">
' This line runs when the browser parses the script
Call WriteGreeting
Sub WriteGreeting
    Dim hr
    hr = Hour(Now)
    If hr < 12 Then
        document.write "Good morning!"
    ElseIf hr < 17 Then
        document.write "Good afternoon!"
    Else
        document.write "Good evening!"
    End If
End Sub
</SCRIPT>
<P>
Another line of body text.
<P>
<SCRIPT LANGUAGE="VBScript">
' These statements are executed at parse-time
document.write "You're visiting at "
document.write Time() & " on " & Date() & "."
</SCRIPT>
</BODY>
</HTML>



 
The second one:

<%@ LANGUAGE = VBScript %>

<HTML>
<HEAD>
<TITLE>Document.Write Examples</TITLE>
</HEAD>
<BODY BGCOLOR=WHITE>
This line is part of the regular body text.
<P>
<%
' This line runs when the browser parses the script
Call WriteGreeting
Sub WriteGreeting
    Dim hr
    hr = Hour(Now)
    If hr < 12 Then
        document.write "Good morning!"
    ElseIf hr < 17 Then
        document.write "Good afternoon!"
    Else
        document.write "Good evening!"
    End If
End Sub
%>
<P>
Another line of body text.
<P>
<%
' These statements are executed at parse-time
document.write "You're visiting at "
document.write Time() & " on " & Date() & "."
%>
</BODY>
</HTML>
HobbyTownAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brunoCommented:
<%@ LANGUAGE = VBScript %> tells the SERVER that the script located between the delimiters <% %> is VBScript.

<SCRIPT LANGUAGE="VBScript"> tells the BROWSER that the following script is VBScript.


so no, your second example will not work, because it's the server tyring to execute that code, not the browser.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HobbyTownAuthor Commented:
Thanks.
0
rdivilbissCommented:
HobbyTown,

Are you aware that only IE supports VBcript?  Non IE browsers visiting that page will not work.

FYI only,
Rod
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

Dave_DietzCommented:
None of this appears to be client side script.

Generally VBScript will be processed on the server (as ASP) and the client really doesn't matter....

Dave Dietz
0
elleonsengaCommented:
Hi

to make the second code works, you have to replace all the "decument.write" with "response.write" as response.write is a function in VBScript but not document.write.

So, your second part of code should be like this:
==================================
<%@ LANGUAGE = VBScript %>

<HTML>
<HEAD>
<TITLE>Document.Write Examples</TITLE>
</HEAD>
<BODY BGCOLOR=WHITE>
This line is part of the regular body text.
<P>
<%
' This line runs when the browser parses the script
Call WriteGreeting
Sub WriteGreeting
    Dim hr
    hr = Hour(Now)
    If hr < 12 Then
        response.write "Good morning!"
    ElseIf hr < 17 Then
        response.write "Good afternoon!"
    Else
        response.write "Good evening!"
    End If
End Sub
%>
<P>
Another line of body text.
<P>
<%
' These statements are executed at parse-time
response.write "You're visiting at "
response.write Time() & " on " & Date() & "."
%>
</BODY>
</HTML>
================================

Hope this helps.
0
brahmankarnikhilCommented:
Hi hobbytown,
the first syntax is (<%@ LANGUAGE = VBScript %>) to specify that the script whatever u r defining should get executed at server side and the second syntax is (<SCRIPT LANGUAGE="VBScript">) to specify that the script whatever u r defining is a client side script. Ur second code snippet is just like ASP (server side execution) & there is no object Document in ASP Objects where as ur first code Client side script in which u've got a object called Document.

That's why ur second code is not working & giving an error!

I hope this will clear ur confusion!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.