How to pass a string variable from SB to inline JS

Just starting out? Need help? Post your questions and find answers here.
the.weavster
Posts: 222
Joined: Sat Mar 01, 2014 3:02 pm

How to pass a string variable from SB to inline JS

Post by the.weavster »

Is it possible to pass a string variable from SB to inline JS?
If so would somebody be kind enough to show me how it's done?
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How to pass a string variable from SB to inline JS

Post by Peter »

Code: Select all

Define myString.s = "World!"

!alert("Hello " + v_myString);
Greetings ... Peter
the.weavster
Posts: 222
Joined: Sat Mar 01, 2014 3:02 pm

Re: How to pass a string variable from SB to inline JS

Post by the.weavster »

Thanks, Peter.

Any idea how to make this work?

Code: Select all

Procedure.s SayHello(myString.s)
  !return "Hello " + v_myString;
EndProcedure

Debug SayHello("Peter")
User avatar
Peter
Posts: 1093
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How to pass a string variable from SB to inline JS

Post by Peter »

this doesn't work at the moment due to this bug: http://forums.spiderbasic.com/viewtopic.php?f=11&t=38

Greetings ... Peter
the.weavster
Posts: 222
Joined: Sat Mar 01, 2014 3:02 pm

Re: How to pass a string variable from SB to inline JS

Post by the.weavster »

Thanks again, Peter.

Why is it necessary to prefix the variable name with 'v_' in the JavaScript code?
Foz
Posts: 20
Joined: Mon Feb 24, 2014 11:25 pm

Re: How to pass a string variable from SB to inline JS

Post by Foz »

because it's internal "compiled" code that you shouldn't be looking at? ;)

I'm guessing to ensure that there isn't a conflict of variable names between all the javascript libraries and your code, so all variables are prefixed with "v_".
Post Reply