Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBScript and Javascript in the same page 2

Status
Not open for further replies.

tictaclam

Programmer
Jan 8, 2004
47
0
0
US
Hi
I'm new to ASP and I was wondering if there is anyway that you can change the asp language from VBScript to Javascript on a page. Basically I'm expanding on someone else's work and their ASP is all in VB and I really need some of the features that javascript offers. i am trying to do <% @Language="VBScript" %>
....code...
<% @Language = "Javascript" %>
.....code...
i'm getting the error: The @ command can only be used once within the Active Server Page.
Is there anyway around this? thanks
 
In my experience with Javascript and ASP to use the Javascript it goes inside an html like tag such as

<script language=javascript>
funciton(){
//some logic here
}
</script>

I would keep the language as it is b/c the ASP will need to run on the server as vbscrip but the JavaScript will be available in the browser.

 
Can you specify those features in JavaScript you need which you cannot find in VBScript?
 
You are dealing with 3 different script conditions:
1. ASP VB Script - interpreted by the server (the "code" as you might call it)
2. VB Script to be interpreted by Internet Explorer (functions, msgboxes, etc.)
3. Javascript to be interpreted by the browser (functions, alerts, etc.)

VB Script is the default script for an ASP. The opening and closing tags being <% & %> VB Script is assumed in between, although it may be defined.

When interpretation by the browser is required, the ASP must either be interrupted or the ASP must perform a response.write of the the client side script (beit VB or Java script). Personally, I find it easier to interrupt the ASP. Perhaps the example below will give you some ideas.

Example:

<%
'asp code here - server interpreted
%>

<script LANGUAGE="JavaScript">
<!--
//javascript goes here - browser interpreted
// -->
</script>

<%
'more asp code here - server interpreted
%>

You can do the same for client side VB Script, but keep in mind most browsers other than IE can't interpret VB Script.
 
Guys,

ASP (server side) accepts both VBScript and JavaScript languages. Just not both at the same time. I think what tictaclam need is the equivalent VBScript for the JavaScript codes he wants to embed/add in an ASP page which already have VBScript codes in it.
 
Do NOT declare your language at the top of any page for server-side script. In fact (though really unbelieveably mimimal) it's a resource drain. Just make sure you write server-side stuff between the <% and the %>

So...At the top of the page DO NOT:
Code:
<%@Language="vbscript"%>
or
Code:
<%@Language="javascript"%>
For Client-Side script ALWAYS:
Code:
<Script Language="vbscript">
'stuff here
</Script>
or
Code:
<Script Language="javascript">
'stuff here
</Script>
 
You can combine them using runat property
Code:
<script language=vbscript runat=server>
Response.Write "test vbscript<br>"
</script>

<script language=javascript runat=server>
Response.Write("test javascript<br>")
</script>

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Hi
using the <script language =javascript>.....</script>. works well for me thanks a lot!
Lisa
 
sorry one more quick question. I am accessing a variable in the javascript html that is defined in the asp, and I am having difficulty making it work. here is my code:
where min = 1

<SCRIPT LANGUAGE = 'JAVASCRIPT'>
var init = <%=min%>
for (i = init; i <= 5; i++)
{
document.write("here");
}

</script>

this doesn't display anything, but it should cycle 5 times. If I print out the value of init it does say 1. Do i need to cast the value or something to make it work in the loop?
thanks
 
sorry nevermind i'm silly i mixed something else up before...this works fine thanks though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top