I use ASP to obtain data from a database and I have a piece of javascript
code I use on my website. I want to use the database variables in my
javascript. I'm not very familiar with javascript, but here is some info
similar to what I'm trying to do.
<%
strFirstName=session("FirstName") ASP code
strLastName=session("LastName")
%>
The javascript code I want to use the variables in.
Items[1]=["First Name", strFirstName,""]
Items[2]=["Last Name", strLastName,""]
Please help or point me to a website with this solution. Thanks much for
your help.
Craig w1****@hotSPAMmail.com (remove SPAM before sending) 16 11173
Craig L wrote: I use ASP to obtain data from a database and I have a piece of javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but here is some info similar to what I'm trying to do.
<% strFirstName=session("FirstName") ASP code strLastName=session("LastName") %>
The javascript code I want to use the variables in. Items[1]=["First Name", strFirstName,""] Items[2]=["Last Name", strLastName,""]
You can't access the ASP variables directly, because ASP is done on the
server, and Javascript is on the client (web browser). By the time the
Javascript is "executing" the ASP has already finished.
You can try this though :-
Items[1]=["First Name", "<%=strFirstName%>",""]
Items[2]=["Last Name", "<%=strLastName%>",""]
HTH!
bengee
I've done something like the following to get ASP variables into javascript
<%
strFirstName = (whatever you want it to equal)
strLastName = (whatever you want it to equal)
Response.Write "<script language=JavaScript>"
Response.Write "var sFirstName=" & strFirstName
Response.Write "var sLastName=" & strLastName
Response.Write "</script>"
Now, the variables sFirstName and sLastName are available to your JavaScript
What you have done, is written a <script> block via ASP that gives you
JavaScript variables....
Mike
"Craig L" <w1******@hotSPAMmail.com> wrote in message
news:w8********************@comcast.com... I use ASP to obtain data from a database and I have a piece of javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but here is some info similar to what I'm trying to do.
<% strFirstName=session("FirstName") ASP code strLastName=session("LastName") %>
The javascript code I want to use the variables in. Items[1]=["First Name", strFirstName,""] Items[2]=["Last Name", strLastName,""]
Please help or point me to a website with this solution. Thanks much for your help.
Craig
w1****@hotSPAMmail.com (remove SPAM before sending)
Bengee:
Thanks for the help. the <%= info didn't help. Do you know if the javascript
code can use it if I create a session object for the variable? I tried some
of this with no luck.
Craig
"bengee" <po********@localhost.localdomain> wrote in message
news:L8******************@wards.force9.net... Craig L wrote: I use ASP to obtain data from a database and I have a piece of
javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but here is some info similar to what I'm trying to do.
<% strFirstName=session("FirstName") ASP code strLastName=session("LastName") %>
The javascript code I want to use the variables in. Items[1]=["First Name", strFirstName,""] Items[2]=["Last Name", strLastName,""]
You can't access the ASP variables directly, because ASP is done on the server, and Javascript is on the client (web browser). By the time the Javascript is "executing" the ASP has already finished.
You can try this though :-
Items[1]=["First Name", "<%=strFirstName%>",""] Items[2]=["Last Name", "<%=strLastName%>",""]
HTH!
bengee
Craig L wrote: Bengee: Thanks for the help. the <%= info didn't help. Do you know if the javascript code can use it if I create a session object for the variable? I tried some of this with no luck.
There's no way Javascript can access an ASP variable. However,
Javascript is the "output" from the ASP code, so you can set a
Javascript variable to be that of an ASP variable. Once this is set
though and being viewed in the browser, you can't change it server-side
without some sort of re-sumbit mechanism.
Have a look a Mike's example below.
bengee
Bengee:
I'm trying what Mike mentioned since it really makes sense; getting ASP to
generate the javascript code, but it doesn't work for me yet. I have the
response.buffer=True set. Not sure what I'm doing wrong.
Craig
"bengee" <po********@localhost.localdomain> wrote in message
news:tH******************@wards.force9.net... Craig L wrote: Bengee: Thanks for the help. the <%= info didn't help. Do you know if the
javascript code can use it if I create a session object for the variable? I tried
some of this with no luck.
There's no way Javascript can access an ASP variable. However, Javascript is the "output" from the ASP code, so you can set a Javascript variable to be that of an ASP variable. Once this is set though and being viewed in the browser, you can't change it server-side without some sort of re-sumbit mechanism.
Have a look a Mike's example below.
bengee
Craig L wrote: Bengee: I'm trying what Mike mentioned since it really makes sense; getting ASP to generate the javascript code, but it doesn't work for me yet. I have the response.buffer=True set. Not sure what I'm doing wrong.
Post some code here then and let us have a look.
Here is my exact code. This page receives a URL as the following
"NewPage.asp?TBLS=AttMarket&TBLS=ConfComment"
In ASP, a reference to Request("TBLS") will return the string
"AttMarket,ConfComment"
I take that info and save it into a JavaScript array that I can access
throughout the page on the client side...
<preliminary HTML stuff>
<body onload="Loaded()">
<%
'-- A bunch of code that means nothing as far as your question goes...
'-- Throw out some JavaScript make it easy to get to the Request
parameters.
Response.Write "<script Language=" & chr(34) & "JavaScript" & chr(34) & ">"
Response.Write "numTables=" & Request("TBLS").Count & ";"
Response.Write "allTables = new Array(" & (Request("TBLS").Count - 1) &
");"
For i = 1 to Request("TBLS").Count
Response.Write "allTables[" & (i - 1) & "] = " & chr(34) &
Request("TBLS")(i) & chr(34) & ";"
Next
Response.Write "</script>"
'-- More code that means nothing
%>
</body>
This is the code generated (from View->Source)
<body onload="Loaded()">
<script Language="JavaScript">numTables=2;allTables = new
Array(1);allTables[0] = "AttMarket";allTables[1] = "ConfComment";</script>
<more html stuff>
</body>
Mike
"bengee" <po********@localhost.localdomain> wrote in message
news:k8******************@wards.force9.net... Craig L wrote: Bengee: I'm trying what Mike mentioned since it really makes sense; getting ASP
to generate the javascript code, but it doesn't work for me yet. I have the response.buffer=True set. Not sure what I'm doing wrong.
Post some code here then and let us have a look.
On Tue, 4 Nov 2003 16:04:04 -0600, in comp.lang.javascript "Mike"
<mb***************@skypoint.com> wrote: | Here is my exact code. This page receives a URL as the following | "NewPage.asp?TBLS=AttMarket&TBLS=ConfComment" | | In ASP, a reference to Request("TBLS") will return the string | "AttMarket,ConfComment" | | I take that info and save it into a JavaScript array that I can access | throughout the page on the client side... | <preliminary HTML stuff> | <body onload="Loaded()"> | <% | | '-- A bunch of code that means nothing as far as your question goes... | | '-- Throw out some JavaScript make it easy to get to the Request | parameters. | Response.Write "<script Language=" & chr(34) & "JavaScript" & chr(34) & ">" | Response.Write "numTables=" & Request("TBLS").Count & ";" | Response.Write "allTables = new Array(" & (Request("TBLS").Count - 1) & | ");" | For i = 1 to Request("TBLS").Count | Response.Write "allTables[" & (i - 1) & "] = " & chr(34) & | Request("TBLS")(i) & chr(34) & ";" | Next | Response.Write "</script>" | | '-- More code that means nothing | | %> | </body>
You are trying to get the javascript to read from the database. This
will not work. You need to do this server-side.
Have a look at http://www.asp101.com/samples/viewas...db%5Fdsn%2Easp
--------------------------------------------------------------- jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
YES, it will work, and it DOES work....
"Jeff North" <jn****@yourpantsbigpond.net.au> wrote in message
news:bg********************************@4ax.com... On Tue, 4 Nov 2003 16:04:04 -0600, in comp.lang.javascript "Mike" <mb***************@skypoint.com> wrote:
| Here is my exact code. This page receives a URL as the following | "NewPage.asp?TBLS=AttMarket&TBLS=ConfComment" | | In ASP, a reference to Request("TBLS") will return the string | "AttMarket,ConfComment" | | I take that info and save it into a JavaScript array that I can access | throughout the page on the client side... | <preliminary HTML stuff> | <body onload="Loaded()"> | <% | | '-- A bunch of code that means nothing as far as your question goes... | | '-- Throw out some JavaScript make it easy to get to the Request | parameters. | Response.Write "<script Language=" & chr(34) & "JavaScript" & chr(34)
& ">"| Response.Write "numTables=" & Request("TBLS").Count & ";" | Response.Write "allTables = new Array(" & (Request("TBLS").Count - 1)
&| ");" | For i = 1 to Request("TBLS").Count | Response.Write "allTables[" & (i - 1) & "] = " & chr(34) & | Request("TBLS")(i) & chr(34) & ";" | Next | Response.Write "</script>" | | '-- More code that means nothing | | %> | </body>
You are trying to get the javascript to read from the database. This will not work. You need to do this server-side.
Have a look at http://www.asp101.com/samples/viewas...db%5Fdsn%2Easp
--------------------------------------------------------------- jn****@yourpantsbigpond.net.au : Remove your pants to reply ---------------------------------------------------------------
Craig L wrote: I use ASP to obtain data from a database and I have a piece of javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but here is some info similar to what I'm trying to do.
<% strFirstName=session("FirstName") ASP code strLastName=session("LastName") %>
The javascript code I want to use the variables in. Items[1]=["First Name", strFirstName,""] Items[2]=["Last Name", strLastName,""]
Please help or point me to a website with this solution. Thanks much for your help.
Craig
w1****@hotSPAMmail.com (remove SPAM before sending)
Trivial:
Items[1]=["First Name", "<%= session('FirstName') %>",""];
Items[2]=["Last Name", "<%= session('LastName') %>",""];
If <%= %> doesn't evaluate properly inside double-quotes (I'm not sure how
ASP deals with this), then you could use something like:
Items[1]=["First Name", <%= dquote(session("FirstName")) %>,""];
Items[2]=["Last Name", <%= dquote(session("LastName")) %>,""];
(where dquote() is a little function that you provide that wraps the passed
string in double-quotes)
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
On Wed, 5 Nov 2003 08:50:38 -0600, in comp.lang.javascript "Mike"
<mb***************@skypoint.com> wrote: | YES, it will work, and it DOES work....
Sorry, I should've replied to Graig L posting.
But my point still stands. You can not use client-side javascript to
read data directly from a database.
| "Jeff North" <jn****@yourpantsbigpond.net.au> wrote in message | news:bg********************************@4ax.com... | > On Tue, 4 Nov 2003 16:04:04 -0600, in comp.lang.javascript "Mike" | > <mb***************@skypoint.com> wrote: | > | > >| Here is my exact code. This page receives a URL as the following | > >| "NewPage.asp?TBLS=AttMarket&TBLS=ConfComment" | > >| | > >| In ASP, a reference to Request("TBLS") will return the string | > >| "AttMarket,ConfComment" | > >| | > >| I take that info and save it into a JavaScript array that I can access | > >| throughout the page on the client side... | > >| <preliminary HTML stuff> | > >| <body onload="Loaded()"> | > >| <% | > >| | > >| '-- A bunch of code that means nothing as far as your question goes... | > >| | > >| '-- Throw out some JavaScript make it easy to get to the Request | > >| parameters. | > >| Response.Write "<script Language=" & chr(34) & "JavaScript" & chr(34) | & ">" | > >| Response.Write "numTables=" & Request("TBLS").Count & ";" | > >| Response.Write "allTables = new Array(" & (Request("TBLS").Count - 1) | & | > >| ");" | > >| For i = 1 to Request("TBLS").Count | > >| Response.Write "allTables[" & (i - 1) & "] = " & chr(34) & | > >| Request("TBLS")(i) & chr(34) & ";" | > >| Next | > >| Response.Write "</script>" | > >| | > >| '-- More code that means nothing | > >| | > >| %> | > >| </body> | > | > You are trying to get the javascript to read from the database. This | > will not work. You need to do this server-side. | > | > Have a look at | > http://www.asp101.com/samples/viewas...db%5Fdsn%2Easp | > | > | > --------------------------------------------------------------- | > jn****@yourpantsbigpond.net.au : Remove your pants to reply | > --------------------------------------------------------------- |
--------------------------------------------------------------- jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Hey Gang:
I'll try what Jeff said to do as soon as I get a chance - probably this
afternoon. Will let you know and post the working code for others.
Craig
"Jeff North" <jn****@yourpantsbigpond.net.au> wrote in message
news:24********************************@4ax.com... On Wed, 5 Nov 2003 08:50:38 -0600, in comp.lang.javascript "Mike" <mb***************@skypoint.com> wrote:
| YES, it will work, and it DOES work....
Sorry, I should've replied to Graig L posting. But my point still stands. You can not use client-side javascript to read data directly from a database.
| "Jeff North" <jn****@yourpantsbigpond.net.au> wrote in message | news:bg********************************@4ax.com... | > On Tue, 4 Nov 2003 16:04:04 -0600, in comp.lang.javascript "Mike" | > <mb***************@skypoint.com> wrote: | > | > >| Here is my exact code. This page receives a URL as the following | > >| "NewPage.asp?TBLS=AttMarket&TBLS=ConfComment" | > >| | > >| In ASP, a reference to Request("TBLS") will return the string | > >| "AttMarket,ConfComment" | > >| | > >| I take that info and save it into a JavaScript array that I can
access| > >| throughout the page on the client side... | > >| <preliminary HTML stuff> | > >| <body onload="Loaded()"> | > >| <% | > >| | > >| '-- A bunch of code that means nothing as far as your question
goes...| > >| | > >| '-- Throw out some JavaScript make it easy to get to the Request | > >| parameters. | > >| Response.Write "<script Language=" & chr(34) & "JavaScript" &
chr(34)| & ">" | > >| Response.Write "numTables=" & Request("TBLS").Count & ";" | > >| Response.Write "allTables = new Array(" &
(Request("TBLS").Count - 1)| & | > >| ");" | > >| For i = 1 to Request("TBLS").Count | > >| Response.Write "allTables[" & (i - 1) & "] = " & chr(34) & | > >| Request("TBLS")(i) & chr(34) & ";" | > >| Next | > >| Response.Write "</script>" | > >| | > >| '-- More code that means nothing | > >| | > >| %> | > >| </body> | > | > You are trying to get the javascript to read from the database. This | > will not work. You need to do this server-side. | > | > Have a look at | > http://www.asp101.com/samples/viewas...db%5Fdsn%2Easp | > | > | > --------------------------------------------------------------- | > jn****@yourpantsbigpond.net.au : Remove your pants to reply | > --------------------------------------------------------------- |
--------------------------------------------------------------- jn****@yourpantsbigpond.net.au : Remove your pants to reply ---------------------------------------------------------------
I think I can get this to a simplier problem now that I have played with it.
Here is what is happening. This code works for what I'm trying to do:
<SCRIPT language=JavaScript>
var strFirstName="Don"
var strLastName="Rose"
</SCRIPT>
<SCRIPT>
Items[0]=[strFirstName, "", ""];
Items[1]=[strLastName, "", ""];
</SCRIPT>
This code getting ASP to write the javascript equivalent like this, doesn't
work:
<%
response.write "<SCRIPT Language=" & chr(34) & "JavaScript" & chr(34)
response.write "var strFirstName=" & chr(34) & "Don" & chr(34)
response.write "var strLastName=" & chr(34) & "Rose" & chr(34)
response.write "</SCRIPT>"
%>
<SCRIPT>
Items[0]=[strFirstName, "", ""];
Items[1]=[strLastName, "", ""];
</SCRIPT>
If I can just get this right, I can get the rest working on my own.
Craig
"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:3F***************@agricoreunited.com... Craig L wrote:
I use ASP to obtain data from a database and I have a piece of
javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but here is some info similar to what I'm trying to do.
<% strFirstName=session("FirstName") ASP code strLastName=session("LastName") %>
The javascript code I want to use the variables in. Items[1]=["First Name", strFirstName,""] Items[2]=["Last Name", strLastName,""]
Please help or point me to a website with this solution. Thanks much for your help.
Craig
w1****@hotSPAMmail.com (remove SPAM before sending) Trivial:
Items[1]=["First Name", "<%= session('FirstName') %>",""]; Items[2]=["Last Name", "<%= session('LastName') %>",""];
If <%= %> doesn't evaluate properly inside double-quotes (I'm not sure how ASP deals with this), then you could use something like:
Items[1]=["First Name", <%= dquote(session("FirstName")) %>,""]; Items[2]=["Last Name", <%= dquote(session("LastName")) %>,""];
(where dquote() is a little function that you provide that wraps the
passed string in double-quotes)
-- | Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at: * http://devedge.netscape.com/library/...ce/frames.html * Internet Explorer DOM Reference available at: * http://msdn.microsoft.com/workshop/a...ence_entry.asp * Netscape 6/7 DOM Reference available at: * http://www.mozilla.org/docs/dom/domref/ * Tips for upgrading JavaScript for Netscape 7 / Mozilla * http://www.mozilla.org/docs/web-deve...upgrade_2.html
Visit the posting "ANS: Using ASP Variables" posted on 11/09/03 for the
solution to this issue.
Craig w1******@hotSPAMmail.com (remove SPAM before emailing).
"Craig L" <w1******@hotSPAMmail.com> wrote in message
news:w8********************@comcast.com... I use ASP to obtain data from a database and I have a piece of javascript code I use on my website. I want to use the database variables in my javascript. I'm not very familiar with javascript, but here is some info similar to what I'm trying to do.
<% strFirstName=session("FirstName") ASP code strLastName=session("LastName") %>
The javascript code I want to use the variables in. Items[1]=["First Name", strFirstName,""] Items[2]=["Last Name", strLastName,""]
Please help or point me to a website with this solution. Thanks much for your help.
Craig
w1****@hotSPAMmail.com (remove SPAM before sending)
Jeff North wrote: You can not use client-side javascript to read data directly from a database.
Depends. There is no native support but an additional API using HTTP
requests could provide access to database on the server and another
one could provide that for a database on the client.
PointedEars
On Mon, 24 Nov 2003 23:04:27 +0100, Thomas 'PointedEars' Lahn wrote: Jeff North wrote:
You can not use client-side javascript to read data directly from a database.
Depends. There is no native support but an additional API using HTTP requests could provide access to database on the server and another one could provide that for a database on the client.
Uh, you still wouldn't be reading the database with JavaScript then would
you?
--
i.m.
The USA Patriot Act is the most unpatriotic act in American history. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: Guy Robinson |
last post by:
I have the code below which parses an expression string and creates tokens.
Can anyone suggest the best of error checking for things like:
Valid variable only obj.attribute -whitespace allowed...
|
by: Steven Scaife |
last post by:
I have decided to re-write the intranet site i created over a year ago. The
coding is pretty awful and hard to read cos I made the mistake of not
putting comments in or putting crappy comments in...
|
by: Sergio Otoya |
last post by:
Hi all,
I need to add an input hidden field to an existing form (post).
I have tried a couple things like adding the '<INPUT type=hidden
name=idSelectedURL value=http://server/documents>' to...
|
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...
|
by: Andy Baxter |
last post by:
Can anyone recommend a good online guide to using objects in javascript?
The book I bought (DHTML Utopia) suggests using objects to keep the code
clean and stop namespace clashes between different...
|
by: Mitesh |
last post by:
Hi all,
I have the following code:
$req = "SELECT * FROM table1";
$res = mysql_query($req);
if(!$res)
return;
|
by: accessbunnie |
last post by:
Hello Access Users!
I am a bit of an Access novice and am currently creating a database and have come up against a huge (for me!) road block.
I do not write in Access code and instead, tend to...
|
by: Luis Zarrabeitia |
last post by:
Quoting Joe Strout <joe@strout.net>:
I'm sure your credentials are bigger than mine. But he is right. A lot of
languages have ditched the "concept" of a static variable on a method (how do
you...
|
by: r0g |
last post by:
Hi There,
I know you can use eval to dynamically generate the name of a function
you may want to call. Can it (or some equivalent method) also be used to
do the same thing for the variables of a...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |