Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: passing variables from javascript to vbscript


Message #1 by "John J Vaughan" <john@j...> on Fri, 27 Jul 2001 11:31:15 -0400
Code that is surrounded by <%%> is ASP code that runs on the server.  By
general conbvention vbscript is the language used for ASP scripting,
although javascript can be used as well.  For server-side scripting, the
language is set with <%@LANGUAGE = "vbscript"%>, which can only be written
once, in the first line of the ASP page.  Server-side scripting is used to
query databases etc and build up the HTML that makes up the page.  It is
processed first, on the server, then the resulting HTML is sent to the
browser.

Once in the browser, the HTML is rendered, and any client side scripting is
executed.  Any kind of event that occurs in the browser (clicking buttons
etc) has to be handled with client side script.  Likewise any manipulation
of the document object model can only be done client side.

Once again, the general convention with client-side scripting is to use
javascript.  If you know that your users all use IE, then you can use
vbscript client-side, but if you want to support other browsers you must use
javascript.

Client side script is delimited by these tags:

<SCRIPT LANGUAGE="javascript">
//javascript goes here
</SCRIPT>

So, sort out your code with the proper script tags so you've got everything
running in the client, and see how you get on.



-----Original Message-----
From: John J Vaughan [mailto:john@j...]
Sent: 27 July 2001 16:31
To: javascript
Subject: [javascript] passing variables from javascript to vbscript


What would be the best way to pass variables from javascript to vbscript?  I
am trying to use cookies, but am having some trouble.  The following code
should set the intial value of a cookie called sMyBGColor to yellow.  Then
when the hyperlink is clicked or the set cookie button is pushed, it gets
changed to red using the function fnSetBGColor.  You can then view the value
of the cookie by using the view cookie button.  It doesn't work tho. . . I'm
a newbie to javaScript, but form what I've read my syntax looks right.
Thanks for the help.

color.asp

<%@LANGUAGE = "JavaScript"%>

<html>

the initial value of sMyBGColor should be yellow<br>
click the hyperlink or the button to change it to red<br><br>

<%
function fnSetBGColor(){
 //set the background color to red
 //and set as a cookie
        document.cookie = "sMyBGColor='#ff0000'";
        alert (document.cookie);


}


var sCookie;
var sColorChoice;
sColorChoise = '#ffff00';  //sets color choice to yellow
sCookie = 'sMyBGColor=' + sColorChoice;
document.cookie = sCookie;
%>

<a href="javascript:void(0)" onClick()="fnSetBGColor()";>Click me to set the
page

color to red</a>
<br><br>
<a href="color2.asp">Click to go to color2.asp and see the new background
color</a>

<br><br>
<center>
<FORM>
 <INPUT TYPE="button" onClick="document.cookie=sCookie;" VALUE="set
cookie";>
 <INPUT TYPE="button" VALUE="display cookie"

onClick="alert(document.cookie);">
</FORM>
</center>

</html>


*****************************************************

color2.asp

<%@LANGUAGE = "VBScript"%>

<html>

<%
dim sMyBGColor
sMyBGColor = request.cookies("sMyBGcolor")

%>

<BODY bgcolor=<%=sMyBGColor%>

</html>

  Return to Index