Transferring values of variables serverside to client side script (directly) 
Author Message
 Transferring values of variables serverside to client side script (directly)

Some mental pipe-rodding requested please.  I need to make a server-side
string value available in client-side VB Script. One way to do this is to
use a hidden field in the HTML as a staging post and reference it from
there, for example document.Myform.Myhidden.value = whatever.

But I always think this is messy, and so I was exploring direct references
inside the <SCRIPT> section, like Myclientside = <%serversidestring%>.

This simplistic structure seems to work - kind of ....

I looked at this code as a test:


<html><head>
<%Dim chunk, jug
chunk = "cat"
jug = 37
response.write "At serverside, chunk is definitely a " & Typename(chunk) &
"<BR>"
response.write "At serverside, jug is definitely a " & Typename(jug) &
"<BR>"
%>
</head><body>
<SCRIPT LANGUAGE=VBScript>
 MsgBox "Chunk has a Typename of " & TypeName(<%=chunk%>), VbOK,
"CLIENTSIDE"
 blatt = CStr(<%=chunk%>)
 MsgBox "Blatt is " & Typename(Blatt), VbOK, "CLIENTSIDE"
 MsgBox "Can I add blatt to the end of this string? - " & Blatt, VbOK,
"CLIENTSIDE"
 MsgBox "Jug has a Typename of " & TypeName(<%=jug%>), VbOK, "CLIENTSIDE"
 blott = CStr(<%=jug%>)
 MsgBox "Blott is " & Typename(Blott), VbOK, "CLIENTSIDE"
 MsgBox "Can I add blott to the end of this string? - " & Blott , VbOK,
"CLIENTSIDE"
</SCRIPT></body></html>

The results are interesting, but I'm not sure I can explain each of them.
Why, importantly, does Chunk test at clientside with a Typename of empty but
jug comes through as an integer?
Any comments about what goes on here in terms of implicit type conversions
would help my understanding considerably and be gratefully received.

The bottom line question though, is what's the correct syntax for getting a
serverside string value available directly in client VBscript section?

As always, many thanks...   - Mike -



Mon, 17 Feb 2003 19:03:54 GMT  
 Transferring values of variables serverside to client side script (directly)
When the page returns to the browser, do View | Source and you'll probably
figure it out.

...TypeName(<%=chunk%>)... will be ...TypeName(cat)...
...TypeName(<%=jug%>)... will be ...TypeName(37)...

Now, at the top of the client side script block, add

chunk = "<%=chunk%>"
jug = <%=jug%>

and change the TypeName lines to

...TypeName(chunk)...
...TypeName(jug)...

and try it again...

--
Michael Harris
Microsoft.MVP.Scripting
--


Quote:
> Some mental pipe-rodding requested please.  I need to make a server-side
> string value available in client-side VB Script. One way to do this is to
> use a hidden field in the HTML as a staging post and reference it from
> there, for example document.Myform.Myhidden.value = whatever.

> But I always think this is messy, and so I was exploring direct references
> inside the <SCRIPT> section, like Myclientside = <%serversidestring%>.

> This simplistic structure seems to work - kind of ....

> I looked at this code as a test:


> <html><head>
> <%Dim chunk, jug
> chunk = "cat"
> jug = 37
> response.write "At serverside, chunk is definitely a " & Typename(chunk) &
> "<BR>"
> response.write "At serverside, jug is definitely a " & Typename(jug) &
> "<BR>"
> %>
> </head><body>
> <SCRIPT LANGUAGE=VBScript>
>  MsgBox "Chunk has a Typename of " & TypeName(<%=chunk%>), VbOK,
> "CLIENTSIDE"
>  blatt = CStr(<%=chunk%>)
>  MsgBox "Blatt is " & Typename(Blatt), VbOK, "CLIENTSIDE"
>  MsgBox "Can I add blatt to the end of this string? - " & Blatt, VbOK,
> "CLIENTSIDE"
>  MsgBox "Jug has a Typename of " & TypeName(<%=jug%>), VbOK, "CLIENTSIDE"
>  blott = CStr(<%=jug%>)
>  MsgBox "Blott is " & Typename(Blott), VbOK, "CLIENTSIDE"
>  MsgBox "Can I add blott to the end of this string? - " & Blott , VbOK,
> "CLIENTSIDE"
> </SCRIPT></body></html>

> The results are interesting, but I'm not sure I can explain each of them.
> Why, importantly, does Chunk test at clientside with a Typename of empty
but
> jug comes through as an integer?
> Any comments about what goes on here in terms of implicit type conversions
> would help my understanding considerably and be gratefully received.

> The bottom line question though, is what's the correct syntax for getting
a
> serverside string value available directly in client VBscript section?

> As always, many thanks...   - Mike -



Tue, 18 Feb 2003 11:32:22 GMT  
 Transferring values of variables serverside to client side script (directly)

Thanks Michael, I did cotton on myself soon after posting my ignorance to
the world. Isn't that often the way? (rhetorical!)

I guess it's better to explicitly force the type you want at the sending
end, e.g.

Mystring = """cat"""
MyDate = "#" & Now & "#"
MyInteger = 37

which means the same code can be used at the client, MyResult =
<%=MyWhatever%>

I'm just a bit surprised this issue isn't mentioned more often in
documentation sources.   - Mike -

Quote:

>When the page returns to the browser, do View | Source and you'll probably
>figure it out.
>...TypeName(<%=chunk%>)... will be ...TypeName(cat)...
>...TypeName(<%=jug%>)... will be ...TypeName(37)...
>Now, at the top of the client side script block, add
>chunk = "<%=chunk%>"
>jug = <%=jug%>
>and change the TypeName lines to
>...TypeName(chunk)...
>...TypeName(jug)...
>and try it again...
>Michael Harris
>Microsoft.MVP.Scripting



>> I looked at this code as a test:


>> <html><head>
>> <%Dim chunk, jug
>> chunk = "cat"
>> jug = 37
>> response.write "At serverside, chunk is definitely a " & Typename(chunk)
&
>> "<BR>"
>> response.write "At serverside, jug is definitely a " & Typename(jug) &
>> "<BR>"
>> %>
>> </head><body>
>> <SCRIPT LANGUAGE=VBScript>
>>  MsgBox "Chunk has a Typename of " & TypeName(<%=chunk%>), VbOK,
>> "CLIENTSIDE"
>>  blatt = CStr(<%=chunk%>)
>>  MsgBox "Blatt is " & Typename(Blatt), VbOK, "CLIENTSIDE"
>>  MsgBox "Can I add blatt to the end of this string? - " & Blatt, VbOK,
>> "CLIENTSIDE"
>>  MsgBox "Jug has a Typename of " & TypeName(<%=jug%>), VbOK, "CLIENTSIDE"
>>  blott = CStr(<%=jug%>)
>>  MsgBox "Blott is " & Typename(Blott), VbOK, "CLIENTSIDE"
>>  MsgBox "Can I add blott to the end of this string? - " & Blott , VbOK,
>> "CLIENTSIDE"
>> </SCRIPT></body></html>

>> The results are interesting, but I'm not sure I can explain each of them.
>> Why, importantly, does Chunk test at clientside with a Typename of empty
>but
>> jug comes through as an integer?
>> Any comments about what goes on here in terms of implicit type
conversions
>> would help my understanding considerably and be gratefully received.

>> The bottom line question though, is what's the correct syntax for getting
>a
>> serverside string value available directly in client VBscript section?

>> As always, many thanks...   - Mike -



Tue, 18 Feb 2003 21:19:55 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ASP referring to server side variables in client side script

2. change value of session variable in client side script

3. Changing values of session variables in client side script

4. How can I transfer a client side variable to server in VBScript

5. Transferring server-side variables to use in client Jscript

6. Server side variables to client side script?

7. Use value of a client side variable??

8. Client Side and Server Side Scripts

9. Pass client script variable to server script variable

10. Mixing of client-side and server-side scripts

11. Server-Side vs Client-Side script

12. Client Side + Server Side Scripts

 

 
Powered by phpBB® Forum Software