Web Hosting Talk







View Full Version : VBScript & JavaScript within same page


adorno
11-25-2002, 04:07 PM
I know some of you JavaScript or VBScript pros may not like this, but I wrote some ASP pages and used some JavaScript within those pages.

My problem is understanding how to share data between the different types of script. Essentially, if I have variables defined by VBScript (using ASP), can I pass any of those variables to a JavaScript? Can the any resulting variables from a JavaScript be used again by the VBScript in my pages.

Thanks...
ea

Rich2k
11-25-2002, 04:49 PM
I tried sharing VBScript and PerlScript in ASP once and I couldn't get the variables to share

MoSupaFly
11-25-2002, 06:21 PM
Originally posted by adornoe

My problem is understanding how to share data between the different types of script. Essentially, if I have variables defined by VBScript (using ASP), can I pass any of those variables to a JavaScript? Can the any resulting variables from a JavaScript be used again by the VBScript in my pages.


I'm a little confused. You say you have variables defined by "VBScript (using ASP)" so it sounds like you're talking about server-side VBScript/ASP code. Correct?

And you want those vars to be accessible to Javascript?

And whatever the javascript codes does... you want those results to be accessible to VBScript?

Okay.... let's get something straight here... are you trying to do the VBScript and JavaScript all on the server-side, or all client-side, or a mixture of both?

Answer that and I'll give you an answer to your question.
:)

adorno
11-26-2002, 02:52 PM
How about server side?

If I do a vbScript and want to pass a variable to a JavaScript, can the variable results from the JavaScript be recognized by VBScript code? How 'bout vice-versa.

Thanks ...
EA

MoSupaFly
11-26-2002, 03:11 PM
Wow... you're using JavaScript for server-side too? You're probably the only person I know that does.

In that case... since we're talking about VBScript and JavaScript both running on the server-side... then unfortunately the bad news is that you can't share vars between the two. :(

Rich2k
11-26-2002, 03:46 PM
Yep I concur the same is true for VBScript and Perl Script

even if you want to use the same form variables you have to read them in using both languages.

ServerCorps
11-27-2002, 01:58 PM
Originally posted by MoSupaFly
Wow... you're using JavaScript for server-side too? You're probably the only person I know that does.

In that case... since we're talking about VBScript and JavaScript both running on the server-side... then unfortunately the bad news is that you can't share vars between the two. :(

Not true. I do it all the time to harness JSCripts' powerful date formatting functions lacking in VBScript.

EXAMPLE:
the ASP Vbscript FormatDate function calls the server side Jscript GetLocalTime function, and returns a string to the calling VBScript Function.

NOTICE THE ENDING OF THE ASP SCRIPT TAGS WHERE THE SERVER SIDE JSCRIPT CODE IS. THIS IS IPORTANT AS THE SCRIPT IS SENT TO THE CLIENT BUT RUN ON THE SERVER. THAT'S THE MAGIC.:dgrin:

%>
<script runat=server language="jscript">

function GetLocalTime(y,M,d,h,mm,s)

{
var d,DateTime='';
d = new Date(y,M,d,h,mm,s);

d.setUTCHours(h,mm,s)

DateTime += d.getVarDate();

//Other possible formats
//DateTime += d.toLocaleDateString();
//DateTime += d.toDateString();
//DateTime += d.toLocaleString();

return DateTime;
}


</script>
<%

Function FormatDate(stime)

dim parts,Timestamp

parts = split(stime,":")

'stime format:
' ms:ss:mm:hh:dd:MM:yyyy
'000:00:00:00:00:00:0000
'month is 0 based index 0=January, 11=December

Dim Times
Times = GetLocalTime(parts(6),parts(5)-1,parts(4),parts(3),parts(2),parts(1))


FormatDate = Times

End Function

MoSupaFly
11-27-2002, 06:31 PM
Originally posted by nikko


Not true. I do it all the time to harness JSCripts' powerful date formatting functions lacking in VBScript.

EXAMPLE:
the ASP Vbscript FormatDate function calls the server side Jscript GetLocalTime function, and returns a string to the calling VBScript Function.

NOTICE THE ENDING OF THE ASP SCRIPT TAGS WHERE THE SERVER SIDE JSCRIPT CODE IS. THIS IS IPORTANT AS THE SCRIPT IS SENT TO THE CLIENT BUT RUN ON THE SERVER. THAT'S THE MAGIC.:dgrin:

[/CODE]

Heh... that's pretty cool. Haven't tried running it but I'll take your word for it. Cool... learn something new :D

ServerCorps
11-27-2002, 06:51 PM
You can trust me. This gets called on average 3-400 times each time one of our admin web pages gets loaded for an app that does real time message queueing. This calculates the age of every queued message relative to ZULU time, which is stored in a DB.

jagorny
06-17-2004, 07:45 PM
This is a fascination of mine... I will add my input, and I hope the others who successfully do this on a regular basis can help with my problem.

Variable can be shared, but only in one direction... in other words, the system loads the default interpreter, then the one you invoke using script runat server.

Example, you have your site set with vbscript as the asp default language in IIS...

You write an ASP page without a @LANGUAGE declaration at the top - it assumes VB and will run the page as is. Say you have a variable you declare - SUPER.

Now say you have a block of code within a script runat server language javascript... it will be able to pick up that variable and chomp it if you want... BUT - say you then spit a variable back and want VB to pick it up again!

Sorry charlie, it won't do it. Why? Because every time it loads a page, IIS will pick and choose which language module to load first, and it only does each language one time.

So, if you have to do something with Javascript and yet need to tap into VBscript later, make sure you declare javascript as the page language and use the script runat container for vbscript later - and don't try to send anything back to javascript later on the page from your vbscript.

HAH actually after writing that I just solved my own problem! [smacks head]