Solved

Interaction between javascript (client side) & asp vbscript on same page

Posted on 2000-03-03
6
205 Views
Last Modified: 2013-11-19
I need to use javascript in an asp page to get the client side date instead of the server.  I can do this and print it on screen.  I then need to use thaat date to go to the server database and get stuff.  I don't seem to be able to call javascript functions from within my asp code so how do I get a value in a variable in the asp code that is equal to the client side date??

Probably easy for someone who knows what they're doing!
0
Comment
Question by:carled
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Expert Comment

by:TTom
ID: 2581865
Seems to me that the problem is not one of language, but of logic.  All your ASP code is processed before anything is sent to the client.  Once the page is sent to the client, the server is "disconnected".

What you could probably do is to send down the page to the client, get the date information at the client, and then "resubmit" the page (as a form) to itself, passing in the client information.

In any case, you are going to have to make another round trip to the server in order to use client side information.

HTH,

Tom
0
 
LVL 8

Expert Comment

by:jbirk
ID: 2583094
You can send client side information via a 1X1 transparent gif with arguments.  I've done this to get a tracker and counter program working.  I use perl to parse the info and return the transparent gif though...


-Josh
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 50 total points
ID: 2584415
Here's an implementation of Ttom's suggestion:

test.asp
--------
<%
if request.querystring("d") = "" then
%>
<HTML>
<script language="javascript">
d = new Date();
document.write("<body onload=\"location.href='test.asp?d=" + d + ";'\"></body>");
</script>
</html>
<% else %>
<html>
<body>
The client thinks it's <%=request.querystring("d")%>
</body>
</html>
<% end if %>

You can also use the single pixel method that Josh suggested under ASP, but you still have the same problem that TTom mentioned-- it requires a trip to the server, so it's not going to be available for the page that it's being displayed on.

You could also use remote scripting.  See the following:

  http://msdn.microsoft.com/scripting/default.htm?/scripting/remotescripting/default.htm
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 1

Author Comment

by:carled
ID: 2585367
Thanks clockwatcher.

Thanks also TTom.  I've given the points to clockwatcher because of the sample script and helpful link.
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 2585425
Thanks.

BTW, I should have escaped the querystring variable.

document.write("<body onload=\"location.href='test.asp?d=" + escape(d) + ";'\"></body>");


0
 
LVL 9

Expert Comment

by:TTom
ID: 2587667
Most welcome.

Tom
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question