VBScript and Javascript1.2 together in an asp page

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.

Thanks,
Ivan
LVL 3
icareyAsked:
Who is Participating?
 
makerpConnect With a Mentor Commented:
you need to place the different languages in different script blocks, for example

<SCRIPT LANGUAGE="VBScript">
  FUNCTION you_vb_function()
   ' blah blah
  END FUNCTION
</SCRIPT>

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

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

OnClick="Javascript:my_js_function();"
0
 
hongjunCommented:
Exactly. You cannot have VBScript blocks and then JavaScript in the VBScript blocks. You need to separate them.

See the way makerp does.

hongjun
0
 
TTomCommented:
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) {
     alert(x)
}
</script>
<script language="VBScript">
function msg(byVal x)
     msgbox x
end function
</script>
</head>
<body>
<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)
   msgbox(x)
end function
</script>

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.



Tom
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
kikkertmCommented:
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>

<script language=javascript RUNAT=server>
</script>

regards,
Mike.
0
 
icareyAuthor Commented:
kikkertm,
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 %>

Thanks,
Ivan
0
 
TTomCommented:
Ivan:

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 %>

and

<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.

Tom
0
 
icareyAuthor Commented:
Tom,
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">
<html>
<head>
      <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 internet.com Corp.  To receive the right to license
* this code to use on your site the original code must be copied from
* Webreference.com. 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 http://webreference.com/dhtml/ 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) {
    setInterval("scrollFrame()",10);
  }
  else {
    setInterval("scrollLayer()",10);
  }
}

function scrollFrame() {
  topFrame.scrollTo(pageXOffset,topFrame.pageXOffset);
}

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

<!--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
      AgriGeneDNS.open 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)
%>
<layer>
<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>
            </tr>
            <%WHILE NOT RS.EOF
                  IF BGColor = "white" THEN
                        BGColor = "#ccffcc"  
                  ELSE                     
                        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>
            </tr>
            <% RS.MoveNext
                  WEND
                        'close the recordset
                        rs.close
                        'close the connection to the database
                        AgriGeneDNS.Close
                        SET rs = nothing
                  %>
</table>

</layer>

<br><br>
<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>
</div>
<% End If %>
</body>
</html>
0
 
TTomCommented:
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.

Tom
0
 
icareyAuthor Commented:
Tom.
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.

Ivan
0
 
TTomCommented:
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.

Tom
0
 
MoondancerCommented:
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
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.

http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20002766.html
http://www.experts-exchange.com/questions/Q.20016343.html
http://www.experts-exchange.com/questions/Q.20108854.html
http://www.experts-exchange.com/questions/Q.20121040.html
http://www.experts-exchange.com/questions/Q.11677820.html
http://www.experts-exchange.com/questions/Q.20156026.html
http://www.experts-exchange.com/questions/Q.20227550.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20169195.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding this question here on closing recommendations if this item remains inactive another three days.
 
Thank you everyone.
 
Moondancer
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.
0
 
icareyAuthor Commented:
did not solve problem
0
 
NetminderCommented:
Admin notified of User neglect. Force-accepted by
Netminder
CS Moderator
0
All Courses

From novice to tech pro — start learning today.