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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Javascript and VBscript be used in the same asp program?

Status
Not open for further replies.

gal

Programmer
Mar 5, 2002
25
US
Can Javascript and VBscript be used in the same asp program? If so, how would you switch back and forth between them? For example, Access table data (VBscript) is being displayed on the same page a Javascript goback button. Thank you!
 
yes they can. All you need to do is enclose the javascript functions as usaul in the script tags and call when they are needed. I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Each time you put a Javascript end tag, would you then need to put a VBscript begin tag in order to use VBscript as well? Or, does it default to script="VBscript" if you assign it up front? Thank you!
 
If you're using ASP. You should be using the <% %> right?
In that case it would be
<%
blah
%>
<script language=&quot;javascript&quot;>
blah
</script>
<%
blah
%>
otherwise then you will have to use the closing tags to stop the javascript portion. The script will not recognize the change in code and will cause a error.
Are the different functions dependant on each other? OR
Are they performing different operations?
Are you in the process of trying this and getting errors or is this a general question?
Also, you can do pretty much everything you want to do in VBscript without ahving to use javascript. Not to step on the javascript gurus I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Thank you, onpnt, for your thorough reply.

So, the only script that needs to be started and stopped is the Javascript? I'm looking to go to a previous page, but do not know the original path. I intend to use this code, but have not tried it yet, as a more experienced person at work said she has not been able to get the combination of Javascript and VBscript to work in the same program.

Can you do the back button in VBscript as well as Javascript? If so, what code do you use? Thanks again.
 
Are you working with VBScript in ASP (server side) and Javascript client side or both client side? Be careful not to confuse server side and client side.

For a back button you can use

<input type=&quot;button&quot; name=&quot;Back&quot; value=&quot;Back&quot; onClick=&quot;window.history.back&quot;>

In your client side HTML (or you could call a javascript function in the onClick event).

To write the above button in ASP, between <% %> (if you don't want to keep leaving and entering server side), use

response.write &quot;<input type=&quot;&quot;button&quot;&quot; name=&quot;&quot;Cancel&quot;&quot; value=&quot;&quot;Cancel&quot;&quot; onClick=&quot;&quot;window.history.back&quot;&quot;>

Hope that's clear.
 
sweevo has it on the button.

I do prefer to use history like this though.
History.Go(-1)
Both will work
I've just had small problems with the .back method I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
best example we can give you is for you to post your code and we can try and show you in the code. Trying to explain things sometimes without the code in the pages you have can make things confusing. I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Gal,

In addition to the other responses to your question, I wanted to add one thing. All ASP does is generate HTML. Regardless of the complexity of your ASP code it will look like normal HTML on the client machine. Consequently, you actually can use javascript inside your VBScript ASP code if you are willing to enclose it in a Response.Write statement. This has been useful to me on several occasions when I wanted to throw a different Javascript onto the page depending on the results of a query or even user input. In keeping with the &quot;Blah&quot; theme, it would look something like this ...

Code:
<% 
Dim blah, blah, blah

Set objDB = blah, blah, blah
Set rsBlah = blah, blah, blah

objDB.open, strBlah,Blah
rsBlah.open &quot;SELECT blah, blah, blah&quot;

If blah = x
 Response.Write &quot;<Script Language=Javascript>Code1</Script>&quot;
Elseif blah = Y
 Response.Write &quot;<Script Language=Javascript>Code2</Script>&quot;
Else
 Response.Write &quot;<Script Language=Javascript>Code3</Script>&quot;
End if

Blah, Blah, Blah
%>

Javascript will conflict with your VBScript if it is inside it, but by putting it in the Response.Write statement the ASP code sees it only as characters to spit out to the client machine. Once the code is on the client machine, however, the VBScript is gone and the Javascript is free to work its magic on your site.

I hope that this makes sense.
Derek
 
Sorry,

Sweevo also wrote about the response.write thing while I was typing my response. I wasn't trying to repeat what he said.

Derek
 
I think I can use the response.write technique to make the back button!

I'm confused about how you would designate client-side VBscript as opposed to the (default?) server-side VBscript, and what types of procedures would be client-side.

Are updating and displaying of database records server side, whereas data validation and hyperlinks are client-side? What things should NOT be done on the same page as the back button?

Hope this will be my last question today. Thank you all for sharing! You are appreciated!!

 
basically the difference between server and client side Vbscript is the tags used to enclose.
Server side would be the <% %>
Client side would be <script type=&quot;VBScript&quot;></script>
Response.Write will not work with Client side VBscript.
You will use the javascript document.write as well in VBscript to write without server use.

All DB functions have to be done server side with ASP or someother form of server side language.
The back button is jsut a function you do in javascript and can be anywhere on any page as long as the function is enclosed in the javascript tags. I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Default HTML script tags define client side script, with the default script language Javascript. As Onpnt says, to change this to client side VBScript, you need to specify the language:

<script type=&quot;vbscript&quot;> but is good practice to use <script type=&quot;javascript&quot;> for that language as well.

Server side will be between <% %> or (just to confuse things but better to clear it up should you encounter it) <script language=&quot;vbscript&quot; runat=&quot;server&quot;></script>.

Client side code controls user interaction and the way the page works dynamically for the user, on their browser on their system. Client side vbscript will only work in Internet Explorer so you should stick with the universally compatible Javascript unless:

a) You really don't know Javascript - but you'd be well advised to at least learn basics.

b) You know for certain that your users only use IE, and you are more happy with VBscript.

c) You don't care.

ASP code runs on your server and actually outputs to the client. What the client sees is only this output, so they don't see any of the ASP if they were to &quot;view source&quot;. For this reason, ASP pages can be viewed in Internet Explorer or Netscape Navigator even though they are produced with VBScript - all the VBScript is run on the server.

I'll also add at this point for completeness (but feel free to ignore) that ASP can also use different languages such as JScript (Microsoft's own Javascript, pretty much the same) or Perlscript. VBscript is the default.

The important thing to do is distinguish between client and server side, and I hope this and the above responses go some way to help...
 
Good point on teh Vbscript and IE sweevo. Never thought of aknowledging that downfall. I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top