Forum Moderators: open

Message Too Old, No Replies

Pass VBScript variable to JScript

         

bateman_ap

12:53 pm on Nov 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, I know I shouldn't be using 2 languages in 1 page but in this rare occassion it can't be helped without an awful lot of reprogramming!

The main part of the page is traditional VB script. however I need to use some JScript on the page. It took me ages to work out but I finally realised I needed to add <script language=JavaScript runat=server> to get it to work and that bit is working fine now.

However I need to pass a varible from my VBScript to the JScript bit.

Ie from a earlier database call I have:
widgetuid = Rs("fld_widget_uid")

Now I need to use this in the JScript code ie:
var currentRestId = widgetuid;

mattur

2:12 pm on Nov 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can pass the VBScript variable to a JSscript function as a parameter, the same way you would with a VBScript function (or sub).

Something like:


<%
widgetuid = Rs("fld_widget_uid")
Call MyJScriptFunction(widgetuid)
%>

<SCRIPT LANGUAGE="JavaScript" runat="server">
function MyJScriptFunction(currentRestId){
//etc
}
</SCRIPT>

bateman_ap

3:14 pm on Nov 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, I must admit though my understanding is still a bit lacking! What kinda thing should I put in //etc

Many thanks

mattur

5:14 pm on Nov 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just put your JScript code in the function where the //etc comment is. By passing the value as parameter "currentRestId" you don't need the assignment:

var currentRestId = widgetuid;

because the widgetuid is now in the currentRestId variable.

So now just do your JS processing on that variable in the JS function. You can also return a value back from JS to your VB code - just treat any JS function as a normal VB function.

bateman_ap

4:37 pm on Nov 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Been trying all weekend to solve this. Doing that just gives loads of errors (the jscript code is about 400 lines long with functions and goodness what else in it. Quite complex stuff.

Never thought it would be so hard to just pass a value!

txbakers

6:58 pm on Nov 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



most of the time you can write a VB function in JScript and vice versa.

Have you thought about writing your JS function into VB to avoid passing them back and forth?

bateman_ap

7:12 pm on Nov 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



400 odd lines of quite complex JScript is rather beyond me to convert to VBScript. If worst comes to worst I suppose I'll hire someone to do it but for one varible to be passed I hoped there would be an easy way!