473,405 Members | 2,445 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,405 software developers and data experts.

executing javascript and vbscript

Hi all--

I'm new to HTML and scripts and am having a problem with some code,
pasted in at the bottom. It uses javascript to get values from a form
in another frame, stores part of an SQL string in a cookie, then uses
vbscript to query a database. The page is reloaded by clicking a button
in another frame.

The problem I'm having is I have to reload the page twice (click the
button twice) before changed values are used. It seems like the
vbscript is executed before the javascript has finished, meaning the
request.cookies("WhereValue") is executed before the cookie value is set
by javascript, so the request pulls the old value. Is something like
this happening? What am I doing wrong here?

If anyone can point me in the right direction, I would appreciate it.

Thanks!
s

=== code ===
'rem -- this line reloads the page that will reflect changes (checkboxes
checked or unchecked.
'
<input type="button"
onclick="parent.frameSylvieResources.location.href ='Sylvie_Resources.asp'"
value="Find these resources">
'rem -- And this is from the page being loaded
'
<html>
<script type="text/javascript">
function GetSelectedCats()
{
strSelected=""
strWhere=""
frmSelectedCats=parent.frameSylvieCategories.docum ent.forms[0].SelCat
for (i=0;i<frmSelectedCats.length;++ i)
{
if (frmSelectedCats[i].checked)
{
strSelected=strSelected+frmSelectedCats[i].id + ", "
}
}
strSelected=strSelected.substr(0,strSelected.lengt h-2)
if (strSelected.length > 0)
{
strWhere = "WHERE (((tblCategorys.fldCategoryID) In (" +
strSelected + "))) "
}
else
{
strWhere = "WHERE (((tblCategorys.fldCategoryID) In (0))) "
}
document.cookie="WhereValue='" + strWhere + "';"
}
</script>

<!--set up and draw the table of resources-->
<script type="text/javascript">
GetSelectedCats()
</script>
<%
strSQL=""
strWherevb=""
strWherevb=request.cookies("WhereValue")
strWherevb=mid(strWherevb,2,len(strWherevb)-2) & " "
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Sylvie"
set rs=Server.CreateObject("ADODB.recordset")
strSQL="SELECT DISTINCT tblResources.fldResourceID,
tblResources.fldResourceTitle, tblCategorys.fldCategoryID "
strSQL=strSQL + "FROM tblResources INNER JOIN (tblCategorys INNER JOIN "
strSQL=strSQL + "tblCategorysResourcesXref ON
tblCategorys.fldCategoryID = "
strSQL=strSQL + "tblCategorysResourcesXref.fldCategoryIDref) ON
tblResources.fldResourceID = "
strSQL=strSQL + "tblCategorysResourcesXref.fldResourceIDref "
strSQL=strSQL + strWherevb + "ORDER BY tblResources.fldResourceTitle;"
rs.Open strSQL, conn
strWherevb=""
%>

<body>
<h4>Resources--select a resource to see the details.</h4>
<table border="1" width=300px>
<%do until rs.EOF%>
<tr>
<td width=10px><input type="radio" name="ResourceMarker"> </td>
<td
width=235px><%Response.Write(rs.fields("fldResourc eTitle").value)%></td>
<!--probably want the get it column to say the format-->
<td width=35px>Get it</td>
<%rs.MoveNext%>
</tr>
<%loop
rs.close
conn.close
%>
</table>
</body>
</html>
May 10 '06 #1
4 1564
gmail wrote:
The problem I'm having is I have to reload the page twice (click the
button twice) before changed values are used. It seems like the
vbscript is executed before the javascript has finished, meaning the
request.cookies("WhereValue") is executed before the cookie value is set
by javascript, so the request pulls the old value. Is something like
this happening? What am I doing wrong here?


Communication between the server and the client happens in one direction at
a time.

First the client makes a request, which includes any cookies that are set,
then the server makes a response (and your ASP is executed on the server),
then the response is received by the client and client side code is
executed.

So the cookie is set using your client side JavaScript AFTER all the cookies
have been sent to the server and AFTER all the server side ASP has been
executed.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
May 10 '06 #2
David Dorward wrote:
The problem I'm having is I have to reload the page twice (click the
button twice) before changed values are used. It seems like the
vbscript is executed before the javascript has finished, meaning the
request.cookies("WhereValue") is executed before the cookie value is set
by javascript, so the request pulls the old value. Is something like
this happening? What am I doing wrong here?


Communication between the server and the client happens in one direction at
a time.

First the client makes a request, which includes any cookies that are set,
then the server makes a response (and your ASP is executed on the server),
then the response is received by the client and client side code is
executed.

So the cookie is set using your client side JavaScript AFTER all the cookies
have been sent to the server and AFTER all the server side ASP has been
executed.

Thanks for the explanation David. I thought it might have something to
do with client vs service side execution.

So is the best way to deal with something like this to use just one
language? And is javascript preferred over vbscript?

cheers!
steve
May 10 '06 #3
gmail wrote:
Thanks for the explanation David. I thought it might have something to
do with client vs service side execution. So is the best way to deal with something like this to use just one
language? And is javascript preferred over vbscript?


There are some things that can be done only on the client. There are
some things that can be done only on the server. There are some things
that can be done on either (and are often best done on the server
first, and then a client side convienience method added afterwards).

On the client side, JavaScript is the only real option. The other
languages that turn up from time to time are VBScript (Internet
Explorer only) and PerlScript (browsers with an uncommon plugin only).

On the server side there are many options, and things mostly come down
to personal preference (since the client doesn't give a monkey's how
the data it recieves is generated).

Going back to your original script, it looks like you have a form, are
sucking the data out of it and putting it into a cookie, then
requesting a new page from the server. This is a long winded and
complicated way of going about things, far simpler would be to just
give the form a regular submit button and submit it (then extract the
data from the query string or post data instead of the cookie).

You also seem to be shoving the data into an SQL server without any
sanity checking - this is an open invitation for someone to inject
whatever SQL they like into your system - so you should probably do
something about that.

May 10 '06 #4
David Dorward wrote:
So is the best way to deal with something like this to use just one
language? And is javascript preferred over vbscript?
[some text snipped]

Going back to your original script, it looks like you have a form, are
sucking the data out of it and putting it into a cookie, then
requesting a new page from the server. This is a long winded and
complicated way of going about things, far simpler would be to just
give the form a regular submit button and submit it (then extract the
data from the query string or post data instead of the cookie).

I'll try that. This is the first time I've tried to do any web-related
coding, so I appreciate the pointer to something more efficient.
You also seem to be shoving the data into an SQL server without any
sanity checking - this is an open invitation for someone to inject
whatever SQL they like into your system - so you should probably do
something about that.

Ok. I'll look into that after I get basic functionality. It's only
local access at this point.

Thanks again!
steve
May 10 '06 #5

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

Similar topics

1
by: Valentina Boycheva | last post by:
Thanks for the reply. I already have "Learning Python" from Mark Lutz and David Ascher, which covers 2.3 (I am in 2.4). However, it seems like heavy artillery to me. What I want is, for instance,...
6
by: John Davis | last post by:
Just wonder if <%@ Language="JAVASCRIPT" %> exists?? Since JavaScript is used in client-side scripting, but <% ... %> is used in server-side scripting. It sounds doesn't make sense. But I saw...
5
by: John Davis | last post by:
When I create new documents in Dreamweaver, there are several choices for ASP creation: ASP JavaScript: run at client side?? ASP VBScript: run at server side?? ASP.NET C# ASP.NET VB I don't...
4
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck...
13
by: Alex Molochnikov | last post by:
Is there any way to find out programmatically if Javascript is supported/enabled in a browser? By "programmatically" I mean on the Java servlet side. TIA Alex Molochnikov Gestalt Corporation
11
by: Doug van Vianen | last post by:
Hi, I often like to include some JavaScript coding in my web pages to make them more interesting. Unfortunately, even when this coding is as simple as a check to see what the display width is in...
10
by: Shadow Lynx | last post by:
That subject packs a whallop, so let me explain in better detail what's happening and how it relates to ASPX pages... In a nutshell, if the first <script /on a page is of type "text/vbscript",...
9
by: Erwin Moller | last post by:
Hi, Can anybody comment on this? In comp.lang.php I advised somebody to skip using: <script language="javascript"> and use: <script type="text/javascript"> And mr. Dunlop gave this response:
2
by: Carlton Kirby | last post by:
I need to execute a job on a SQL Express 2005 instance (no SQLAgent). The job will be executed manually by a user, so it doesn't need to be scheduled to run automatically. I thought I could...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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
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.