| home / programming / javascript / vbscript |
[next] |
|
Using Server-Side VBScript with Client-Side JavaScriptBy Jerry Gray (grgray@cmsenergy.com)Since the first article was published I continue to receive questions on this topic. I thought it would be helpful to cover some of the most common questions that readers have had.
I will also discuss why timing is so important when using these two scripting languages together. Sharing CookiesUsing cookies is one of the easiest ways to maintain state throughout a user's session, (providing the user accepts cookies). I like to set them using client-side JavaScript, perhaps when a user has clicked on something. Let's use a fairly simple example where a user sets the background color of the page they are viewing. The html to set this up would look something like this:
And the associated JavaScript function would look something like this:
If we want to set a cookie that remembers that the user set the bgcolor we just change our function to create a cookie called mybgcolor, and set it to the same color that we used for the background:
If the user goes to another page on our site we can check to see if they set the background color by reading the value of the cookie, and draw our new page accordingly. We can also use JavaScript to retrieve cookie values, but for the sake of this example we will retrieve the value using VBScript. We can read the value of our cookie using VBScript like this:
Then set the background by referencing the variable in the body tag like this:
Here are some more short cookie examples to set a cookie in VBScript, and to read a cookie in JavaScript. To set a cookie in VBScript:
To read a cookie in JavaScript:
As you can see, cookies do not care what language their are written in. Once a cookie exists you should be able to retrieve its value using any other language’s protocols for doing so.
|
| home / programming / javascript / vbscript |
[next] |
| ||||||||||||||||||||
Created: February 12, 2001
Revised: February 21, 2001