VBScript and Javascript1.2 together in an asp page

Posted on 2001-07-24
Last Modified: 2008-02-26
Is it possible to have VBScript and Javascript1.2 together in an asp page?

I had a page with a Javascript1.2 script in it, then added a VBScript to it that access an access database.
Now it appears that the Javascript1.2 no longer works.

Question by:icarey
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 10

Accepted Solution

makerp earned 100 total points
ID: 6311867
you need to place the different languages in different script blocks, for example

  FUNCTION you_vb_function()
   ' blah blah

<SCRIPT LANGUAGE="Javascript">
  function my_js_function()
    // blah blah

then when you make calls you can prefix the call like this

LVL 33

Expert Comment

ID: 6312083
Exactly. You cannot have VBScript blocks and then JavaScript in the VBScript blocks. You need to separate them.

See the way makerp does.


Expert Comment

ID: 6312864
These two blocks of script peacefully coexist in my (test) web age, and clicking either <div> displays the appropriate alert.  There seems to be no need to prefix the function call with a particular language.  However, as noted, you will need to separate the script blocks.

<script language="JavaScript">
function msgbox(x) {
<script language="VBScript">
function msg(byVal x)
     msgbox x
end function
<div onclick="msgbox('JavaScript alert');">JavaScript</div>
<div onclick="msg('VBScript alert');">VBScript</div>

An interesting variation on this, which should work, would be to call the JavaScript function from the VBScript function (or vice-versa), e.g.

<script language="VBScript">
function msg(byVal x)
end function

In this case, the VBScript function is calling the previously defined JavaScript function.  Other than possible syntactical confusion (i.e., a JavaScript function named "msgbox", there is no reason why this sort of thing should not work.  I have seen it done many times.

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.


Expert Comment

ID: 6317634
I think icarey is talking about serverside scripting ("Is it possible to have VBScript and Javascript1.2 together in an asp page?").
That should also be possible although you should take care to keep it seperated too.

<% @language=vbscript %>

<% vbstuff %>

<% @language=javascript %>

<% javascriptstuff %>

I never really tried it, but if it works, this is probably the way to do it.

Another possibility is:

<script language=vbscript RUNAT=server>

<script language=javascript RUNAT=server>


Author Comment

ID: 6321317
The vbscript is server side and the javascript is client side.
I have a table that is dynamically filled from an access database. This table is inside <layer></layer>
The <layer></layer> is for the benifit of Netscape 4.
I have 2 frames on the page.
The javascript allows the scrolling of the bottom frame to control the scrolling of the top frame.
I have placed the javascript in the <head></head> and all <%@ Language=VBScript %> in the body. the table is in the <%@ Language=VBScript %>


Expert Comment

ID: 6326609

In that case, the VBScript (on the server side) is processed before the JavaScript exists!  This is not a question of VBScript vs. JavaScript, but one of client side vs. server side.  The only way to have the program communicate these values is via HTML form submissions.

FWIW, Mike's comment above is not quite correct.  You can only have a single ASP language declaration in a page.  To use multiple languages, you must use a combination of

<% @ language = PrimaryLanguage %>


<script runat=Server language = SecondaryLanguage></script>

Would have to see your code and get some more information about what is not working in order to arrive at a solution.


Author Comment

ID: 6329270
Here is the code. Is there any problem associated with the fact that I have installed ASP.NET beta2. I did read that only vbscript can exist in a page.

<!--- This Page accepts the BullBreed URL variable from dairyproofsframe.asp template.
        It Checks if the variable exists.
        If it does the corresponding details are displayed from the appropriate table.
        Else the user is returned back to the noqrystr.asp error page --->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <title>Proofs Table</title>
      <LINK rel="StyleSheet" type="text/css" href="../../css/tables.css">
      <SCRIPT LANGUAGE="Javascript1.2">
/* syncFrames.js (Cross-browser Synchronized Frames)
* Copyright (c) 1999-2000 Corp.  To receive the right to license
* this code to use on your site the original code must be copied from
* License is granted if and only if this entire copyright
* notice is included, and you link from the page on which the code is used
* to Webreference at for the latest version.
* By Peter Belesis. v1.0 980325 - column 17.

var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

//if NS 4+
if (browser_type=="Netscape"&&browser_version>=4)
   onload = checkScroll;
//if IE 4+
else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4)
   onscroll = keepTogether;

topFrame = parent.frames.headerframe; // change name

function keepTogether(){
  topFrame.document.body.scrollLeft = document.body.scrollLeft;

function checkScroll() {
  if (topFrame.scrollbars.visible) {
  else {

function scrollFrame() {

function scrollLayer() {
  topFrame.document.layers[0].left = -pageXOffset;
<body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">
<%@ Language=VBScript %>
<% URLString1 = Request.QueryString("BullBreedID")
If IsEmpty(URLString1) then
      Response.Redirect "../../noqrystr.asp"
'each time the case is fulfilled, the specific
'the variable BreedTable is given a value
    CASE "IS"
    CASE "AY"
    CASE "SB"
      CASE "DS"
      CASE "FF1"
      CASE "FF2"
      CASE "FF3"
      CASE "FF4"
      CASE "JY1"
      CASE "JY2"
      CASE "JY3"
      CASE "MO"
      CASE "NO"

<!--this asp object is used to connect to the database-->
<OBJECT RUNAT=server PROGID=ADODB.Connection id=AgriGeneDNS> </OBJECT>
      'create an instance of the connection object Session("ConnectionString")

SQL_Select1 = "SELECT " & BreedTable & ".[BULL ID] as BULLID, " & BreedTable & ".[BULL NAME] as BULLNAME, " & BreedTable & ".SRCE, " & BreedTable & ".APR, "  & BreedTable & ".REL,"
SQL_Select2 = " " & BreedTable & ".ASI, " & BreedTable & ".PROT, " & BreedTable & ".[PROT%] as PROTPER, " & BreedTable & ".MILK, " & BreedTable & ".FAT,"
SQL_Select3 = " " & BreedTable & ".[FAT%] as FATPER, " & BreedTable & ".REL1, " & BreedTable & ".[RIP%] as RIPPER, " & BreedTable & ".[OVER TYPE] as OVERTYPE, " & BreedTable & ".[MAM SYST] as MAMSYST,"
SQL_Select4 = " " & BreedTable & ".REL2, " & BreedTable & ".[MILK SPD] as MILKSPD, " & BreedTable & ".TEMP, " & BreedTable & ".[LIKE] as LIKES, " & BreedTable & ".REL3, BullPrices.StrawPrice"
SQL_From = " FROM " & BreedTable & " INNER JOIN BullPrices ON " & BreedTable & ".[Bull ID] = BullPrices.BullCode"
SQL_Where = " WHERE BullPrices.BullBreed_ID='"
SQL_Order = " ORDER BY " & BreedTable & ".[Bull Name];"
SQL_query = "" & SQL_Select1 & SQL_Select2 & SQL_Select3 & SQL_Select4  & SQL_From  & SQL_Where & URLString1 & "'" & SQL_Order &""

'execute the sql query
Set RS = AgriGeneDNS.Execute(SQL_query)
<table frame="box" border="1" cellspacing="0" cellpadding="5">
            <tr bgcolor="teal">      
                  <th nowrap><font color="white">BULL CODE</font></th>
                  <th nowrap><a href="dairyproofs.asp?BullBreed=BullBreed" target="detailframe"><font color="yellow">BULLNAME</font></a></th>                  
                  <th nowrap><font color="white">PEDIGREE</font></th>                   
                  <th nowrap><font color="white">SRCE</font></th>
                  <th nowrap><a href="sortapr.asp?BullBreed=BullBreed" target="detailframe"><font color="yellow">APR</font></a></th>
                  <th nowrap><a href="sortrel.asp?BullBreed=BullBreed" target="detailframe"><font color="yellow">REL</font></a></th>
                  <th nowrap><font color="white">ASI</font></th>
                  <th nowrap><font color="white">PROT</font></th>
                  <th nowrap><font color="white">PROT%</font></th>
                  <th nowrap><a href="sortmilk.asp?BullBreed=BullBreed" target="detailframe"><font color="yellow">MILK</font></a></th>
                  <th nowrap><font color="white">FAT</font></th>
                  <th nowrap><font color="white">FAT%</font></th>
                  <th nowrap><font color="white">REL1</font></th>
                  <th nowrap><a href="sortripper.asp?BullBreed=BullBreed" target="detailframe"><font color="yellow">RIP%</font></A></th>
                  <th nowrap><font color="white">OVER TYPE</font></th>
                  <th nowrap><font color="white">MAM SYST</font></th>
                  <th nowrap><font color="white">REL2</font></th>
                  <th nowrap><font color="white">PRICE</font></th>
                  <th nowrap><font color="white">MILK SPD</font></th>
                  <th nowrap><font color="white">TEMP</font></th>
                  <th nowrap><font color="white">LIKE</font></th>
                  <th nowrap><font color="white">REL3</font></th>
            <%WHILE NOT RS.EOF
                  IF BGColor = "white" THEN
                        BGColor = "#ccffcc"  
                        BGColor = "white"
                  END IF%>                        
            <tr BGCOLOR=<%= BGColor %>>      
                  <td nowrap><%=rs("BULLID")%></td>
                  <td nowrap><%=rs("BULLNAME")%></td>
                  <td nowrap>PEDIGREE</td>                   
                  <td nowrap><%=rs("SRCE")%></td>
                  <td nowrap align="right"><%=rs("APR")%></td>
                  <td nowrap align="right"><%=rs("REL")%></td>
                  <td nowrap align="right"><%=rs("ASI")%></td>
                  <td nowrap align="right"><%=rs("PROT")%></td>
                  <td nowrap align="right"><%=rs("PROTPER")%></td>
                  <td nowrap align="right"><%=rs("MILK")%></td>
                  <td nowrap align="right"><%=rs("FAT")%></td>
                  <td nowrap align="right"><%=rs("FATPer")%></td>
                  <td nowrap align="right"><%=rs("REL1")%></td>
                  <td nowrap align="right"><%=rs("RIPPer")%></td>
                  <td nowrap align="right"><%=rs("OVERTYPE")%></td>
                  <td nowrap align="right"><%=rs("MAMSYST")%></td>
                  <td nowrap align="right"><%=rs("REL2")%></td>
                  <td nowrap align="right"><%=rs("STRAWPRICE")%></td>
                  <td nowrap align="right"><%=rs("MILKSPD")%></td>
                  <td nowrap align="right"><%=rs("TEMP")%></td>
                  <td nowrap align="right"><%=rs("LIKES")%></td>
                  <td nowrap align="right"><%=rs("REL3")%></td>
            <% RS.MoveNext
                        'close the recordset
                        'close the connection to the database
                        SET rs = nothing


<Div align="bottom">
      <hr size="2" width="95%"><br>
      <img src="../../graphics/arrows/cyuarrup.gif" height="31" width="31" align="right" alt="Up" onclick="window.scrollTo(0,0)">
      &nbsp;&nbsp;<a href="../../dairy.cfm" target="pageframe"><font color="990000">Back To Dairy Bull Breeds</font></a>
<% End If %>

Expert Comment

ID: 6330212
Hmmm.  It appears that you are dealing inside a frameset.  If that is the case, passing information into the page is going to be a potential point of failure.  The page where the information is coming from must target the frame where your page is intended to populate, or the variable from the previous page (the URL?) will not populate properly.

If I were you, I would work with the pages outside the frameset to be sure that the variables are being passed properly, and then try to accomplish this inside the frames.  I'm guessing that is where your problem is occurring.


Author Comment

ID: 6330532
Thanks for your comments.
The table populates correctly, the problem is that the javascript does not work with vbscript. That is one frame now does not control the scrolling of another frame.

This javascript code works fine with Cold Fusion tags.


Expert Comment

ID: 6331411
I'm real curious about what's going on here.

The server side code (ASP/VBScript) will render "plain vanilla" HTML to the browser.  If you check the source of the ASP page (rendered in the browser), I don't think you will find any VBScript.

In fact, save a copy of the rendered ASP page (with the table created) and see if you can determine why the JS is not working.  Take the ASP out of the mix temporarily.

There is no logical reason for this.

Hmmm.  I just noticed something in your code.  The language declaration for the ASP page (<% @ language = VBScript %> is somewhere in the middle of the code.  From what I know, this statement must be the FIRST statement in the code (although I actually think you can get away without it).  Try moving it above all your HTML and JavaScript and see what that does.

I still think you need to examine the HTML which is rendered in the browser to get a better idea of what is going on.


Expert Comment

ID: 6842779
Question(s) below appears to have been abandoned. Your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question. Again, please comment to advise the other participants why you wish to do this.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, in the event new items have been created since this listing was pulled.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

------------>  EXPERTS:  Please leave any comments regarding this question here on closing recommendations if this item remains inactive another three days.
Thank you everyone.
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.

Author Comment

ID: 6846976
did not solve problem

Expert Comment

ID: 6903241
Admin notified of User neglect. Force-accepted by
CS Moderator

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to alternate between 2 messages until page closes in Classic ASP 8 41
ASP server side get value 15 47
Executing a script on a timer online 5 32
ASP exit 10 28
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question