473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ANS: Using ASP Variables

This is a solution followup to a request for help posted on 11/04/03 at
12:51pm titled "Using ASP Variables". Here is how you can make ASP variables
available for use in Javascript code. I hope you find this info as valuable
as I did. Thanks to everyone who helped me get to this solution with their
wonderful ideas.

1) Create session objects for the variables (this example provides strings,
but they could come out of a database):

<!-- Get data for Session Objects -->
<%
session("Firstname")="Mary"
session("Lastname")="Thomas"
%>

2) Create string values:

<!-- Set string values -->
<%
sFirstname=session("Firstname")
sLastname=session("Lastname")
%>

3) Use response.write to create the Javascript code:

<!-- Create Javascript variables -->
<%
response.write "<SCRIPT Language=" & chr(34) & "JavaScript" & chr(34) & ">"
response.write "var strFirstname=" & chr(34) & sFirstname & chr(34) &";"
response.write "var strLastname=" & chr(34) & sLastname & chr(34) &";"
response.write "</SCRIPT>"
%>

4) Now, strFirstname and strLastname values are avail for us in other
Javascript code.

Since I have the ASP to JS issue solved, I will work on the JS to ASP issue
soon. Thanks.

Craig

w1******@hotSPAMmail.com (remove SPAM before emailing.)

Jul 20 '05 #1
2 4235


Craig L wrote:
This is a solution followup to a request for help posted on 11/04/03 at
12:51pm titled "Using ASP Variables". Here is how you can make ASP variables
available for use in Javascript code. I hope you find this info as valuable
as I did. Thanks to everyone who helped me get to this solution with their
wonderful ideas.

1) Create session objects for the variables (this example provides strings,
but they could come out of a database):

<!-- Get data for Session Objects -->
<%
session("Firstname")="Mary"
session("Lastname")="Thomas"
%>

2) Create string values:

<!-- Set string values -->
<%
sFirstname=session("Firstname")
sLastname=session("Lastname")
%>

3) Use response.write to create the Javascript code:

<!-- Create Javascript variables -->
<%
response.write "<SCRIPT Language=" & chr(34) & "JavaScript" & chr(34) & ">"
response.write "var strFirstname=" & chr(34) & sFirstname & chr(34) &";"
response.write "var strLastname=" & chr(34) & sLastname & chr(34) &";"
response.write "</SCRIPT>"
%>

4) Now, strFirstname and strLastname values are avail for us in other
Javascript code.

Since I have the ASP to JS issue solved, I will work on the JS to ASP issue
soon. Thanks.


That is far from being solved, imagine the ASP string value has double
quotes in it, then your approach breaks and you get a client side script
error. Or imagine the ASP string value contains a line break, your code
would then Response.Write that line break and again you get a client
side script error. So do some work on escaping certain characters first.
Not to speak about variables of other types, the subject speaks about
ASP variables so your code should be able to deal with numbers,
booleans, maybe dates.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen wrote on 10 nov 2003 in comp.lang.javascript:
Not to speak about variables of other types, the subject speaks about
ASP variables so your code should be able to deal with numbers,
booleans, maybe dates.


Last night the OP could have had a date with a ASP variable.

;-)

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hal Vaughan | last post by:
First, I am aware of both SwingUtilities.invokeLater(), and of using Thread to create a new thread.  These are part of the problem. I want to have something running in the background, while the...
11
by: Fred Bennett | last post by:
I have a simulation project in which data can naturally be held in structures for processing. There are calls to multiple functions involved. Execution speed is an issue. Do I take a big hit for...
4
by: jhonyxxx | last post by:
I have the next programa in C++: #include <iostream.h> // C++ I/O routines #include <list.h> // The STL list class #include<stdio.h> #include <string.h> typedef struct { char nombre; int...
0
by: Namratha Shah \(Nasha\) | last post by:
Type Library Importer : tlbImp This tool is used to convert the type library definitons found in COM components to .NET assembly. This tool works on the entire type library at the same time...
17
by: Davíđ Ţórisson | last post by:
now in my web I have some global variables to be used in many different subpages, in the old ASP I simply loaded a variables.asp file into memory using the eval() function. Now I'd like to use XML...
0
by: sang | last post by:
Hi I want to lock the table with both read and write there is no action held after lock the table. I know how to lock the table with read and write, lock table mytable read; lock table...
6
by: angellove40 | last post by:
Q.1>Write a program to print the following output using for loops 1 2 2 3 3 3 4 4 4 4 ...
1
by: rekhasc | last post by:
if you know the ans plz heighlite that ans 3. Interoperability classes include a. System.Runtime.InteropServices b. System.Runtime.InteropServices.CustomMarshallers...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.