473,409 Members | 1,945 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,409 software developers and data experts.

javascript + database

Hi

I want to write code in Javascript which pulls out entries from a database
via a for loop. Essentially what I am trying to do is something like:

//setting up database connection
<%
Set cnn = ...
filePath = ...
cnn.Open ....
Set rst = ...
sqlquery = "SELECT ....."
rst.open sqlquery, cnn, 2, 2
%>

//Javascript code
<SCRIPT LANGUAGE = "JavaScript">
<!--
.....
function test()
{
document.Insurance.county.length = 10;
for (var x = 1; x <= 10; x++)
{
document.Insurance.county[x].value = rst("County_ID");
document.Insurance.county[x].text = rst("County");
rst.next();
}
}
.....
--!>

Is something like this possible or am I doing something incorrect here? This
is part of a code for a form where "County" is a dropdown. So instead of
hardcoding the values for "County_ID" and "County", I want to write a for
loop which loads the values to be displayed in the dropdown from the
database. Any help/hints/suggestions would be highly appreciated...

Navodit
Apr 11 '07 #1
5 2466
Navodit wrote on 11 apr 2007 in comp.lang.javascript:
Hi

I want to write code in Javascript which pulls out entries from a
database via a for loop. Essentially what I am trying to do is
something like:

//setting up database connection
<%
Set cnn = ...
filePath = ...
cnn.Open ....
Set rst = ...
sqlquery = "SELECT ....."
rst.open sqlquery, cnn, 2, 2
%>

//Javascript code
<SCRIPT LANGUAGE = "JavaScript">
<!--
....
function test()
{
document.Insurance.county.length = 10;
for (var x = 1; x <= 10; x++)
{
document.Insurance.county[x].value = rst("County_ID");
document.Insurance.county[x].text = rst("County");
rst.next();
}
}
....
--!>

Is something like this possible or am I doing something incorrect
here? T
You are disregarding serverside and clientside script.

Serverside asp can be either vbscript or j[ava]script, but is executed on
the server, where your database resides.

rhe resiult of rst("County_ID") is only available on the server script,
unless you port it as a inline string to the client:

var C-id = "<% = rst("County_ID") %>";

but on the client rst.next(); means nothing at all.

Serverside code results in a html [+ clientside code] stream to the
client where the html and the clientside code are interpreted by the
browser. The serverside code is finished before that.
Apr 11 '07 #2
Is something like this possible or am I doing something incorrect
here? This is part of a code for a form where "County" is a dropdown.
So instead of hardcoding the values for "County_ID" and "County", I
want to write a for loop which loads the values to be displayed in the
dropdown from the database. Any help/hints/suggestions would be highly
appreciated...
You ASP code is running on the server-side and the javascript on the
client-side so the javascript can't use directly your ASP rst object.

One way is to put the rst data into an hidden field and then from
javascript, extract the data from the hidden field.

One example at :
http://www.rgagnon.com/jsdetails/js-0117.html

Bye.
--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html
Apr 11 '07 #3
On Apr 11, 1:18 pm, Real Gagnon <realgag+use...@geocities.comwrote:
Is something like this possible or am I doing something incorrect
here? This is part of a code for a form where "County" is a dropdown.
So instead of hardcoding the values for "County_ID" and "County", I
want to write a for loop which loads the values to be displayed in the
dropdown from the database. Any help/hints/suggestions would be highly
appreciated...

You ASP code is running on the server-side and the javascript on the
client-side so the javascript can't use directly your ASP rst object.

One way is to put the rst data into an hidden field and then from
javascript, extract the data from the hidden field.

One example at :http://www.rgagnon.com/jsdetails/js-0117.html

Bye.
--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
*http://www.rgagnon.com/howto.html
*http://www.rgagnon.com/bigindex.html
Try loading your recordset into an array then converting the asp array
to javascript, check out
http://www.aspfree.com/c/a/ASP/Conve...d-Venkatraman/

Apr 11 '07 #4
On Wed, 11 Apr 2007 12:01:05 -0500, Navodit wrote:
Is something like this possible or am I doing something incorrect here?
This is part of a code for a form where "County" is a dropdown. So
instead of hardcoding the values for "County_ID" and "County", I want to
write a for loop which loads the values to be displayed in the dropdown
from the database. Any help/hints/suggestions would be highly
appreciated...
As others have suggested you may need to read up on the client/server
model for programming web applications.

The only way for JavaScript to be able to see your server-side data is to
pass it to the client using your server-side script.

You do this by having the server-side script create the client-side
javascript:

<?
$test_var = "I am a test variable";
echo "<script type='text/javascript'>";
echo "var test = $test_var;";
echo "</script>";
?>

This will leave you with a client-side variable "test" that has been
loaded with data from the server-side variable "test_var".
Apr 11 '07 #5

"Ivan Marsh" <an*****@you.nowwrote in message
news:pa****************************@you.now...
On Wed, 11 Apr 2007 12:01:05 -0500, Navodit wrote:
>Is something like this possible or am I doing something incorrect here?
This is part of a code for a form where "County" is a dropdown. So
instead of hardcoding the values for "County_ID" and "County", I want to
write a for loop which loads the values to be displayed in the dropdown
from the database. Any help/hints/suggestions would be highly
appreciated...

As others have suggested you may need to read up on the client/server
model for programming web applications.

The only way for JavaScript to be able to see your server-side data is to
pass it to the client using your server-side script.

You do this by having the server-side script create the client-side
javascript:

<?
$test_var = "I am a test variable";
echo "<script type='text/javascript'>";
echo "var test = $test_var;";
echo "</script>";
?>

This will leave you with a client-side variable "test" that has been
loaded with data from the server-side variable "test_var".
echo "var test = '$test_var';";
Apr 11 '07 #6

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

Similar topics

3
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
4
by: SuperPippin | last post by:
Hello all ! I am a bluebit in JavaScript. I would like to write a little program to read data in a MySQL database. What do I need ? Is there a specific "JavaScript Include" to make this work ?...
1
by: vishnu mahendra | last post by:
i am new to javascript. Can any one please tell me how to connect javascript to oracle in windows 98 using apache.where i could get information on connecting? thank you in advance, vishnu
3
by: Scott Castillo | last post by:
Is it possible to access an SQL Server database from a Javascript client? I know you can transfer variables from middleware to Javascript client, but was wondering if you can directly access...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
2
by: megabyte | last post by:
Hello; I have an ASP application which gathers information to put in a database via some forms - I would like to do the form validation (making sure some fields are not empty) with a Javascript...
3
by: IntraRELY | last post by:
I need to attach the following 2 little scripts to an ASP.NET Button. I am having an issue with running both of the Attributes.Add. I can only get on to work at once. I have also tried to put them...
2
by: Methis Elddir | last post by:
Can javascript be used to build a web-based front end to a local database? I wrote an application for a client that controls a series of medical devices. It runs a series of tests, collects...
2
by: haft | last post by:
My webpage of discussion contains a javascript powered image gallery of small thumbnail images that when moused-over, display a larger image that corresponds to the current moused-over thumbnail....
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
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...
0
agi2029
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,...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.