Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get Javascript var to an ASP var 1

Status
Not open for further replies.

JohannIcon

Programmer
Sep 3, 2002
440
MT
Dear All,

I do not know if this is the right forum, but I wish to get a Javascript variable to an ASP var so that I can insert it into a database.

I have the following Javascript to get the URL of the page:-

<script language=&quot;jscript&quot;>
var temp = window.location.href.split(&quot;?&quot;);
document.write (temp);
</script>

and I want to insert temp into an MSAccess table

Can you please help

Thanks
 
i tend to create a form and add the variable to a hidden element and then submit the form...another option is to append the var to the url being linked to and using request.querystring to access that var

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
I don't wish to submit the form. The main idea is not to submit the form, cause if I wanted to submit the form, then I would have used the Request.ServerVariables(&quot;HTTP_REFERER&quot;) from the beginning!
 
JohannIcon can you please explain what you're doing a bit more. what you need dosen't make much sense to me after the not wanting to submit the form comment. if you're calling a server script int eh first place what's the difference if you dynamically submit a form to get your values there? either way you're going to need to get a call made to the server and a HTTP request will need to be done

_____________________________________________________________________
onpnt2.gif

Hakuna matata!!
 
If you're client base is restricted to IE browsers only you can use XML or use javascript to open a popup that calls an asp page and then closes itself straight away.

In your javascript routine
window.open('pagename.asp?var=<%=someaspvar%>,'')}

Then you have an asp page called pagename.asp
<%
var=request(&quot;var&quot;)
'and add to database
%>

This is at clientside with some action calling the javascript routine but confused slightly since you're javascript is running on page load so I don't see any reason why you can't just do this with asp where it happens.

ASP is executed on the server first so your javascript can't pass anything back to the asp code.

 
Ok, what I am doing basically is a simple banner system. I have three banners appearing on a page, can be index.asp, or news.asp etc, and i wish to retreive the URL of that site and insert it into the database, so that the client knows that his banner was visible at a given time on the page that it has been displayed.

I hope I was clear in my explanation
 
No one can help me? Is there a way how I can retrieve the URL of a page without redirecting it to another page?
 
You mean if someone clicks the banner of an external site you want to know what banner was clicked?
Simple - when they click the banner it should go to another page on your site passing the site name of the banner they clicked. Update the db and then do
response.redirect &quot;
 
No no I already do that, when he clicks on the banner, I am sending him to another asp page where I am getting all the vars and then redirecting to the appropriate page (of the banner)

What I want to know is, when the banner is displayed on my page, for example index.asp, or news.asp, I get the name of the page!
 
Imagine I have a page in my website, called and it contains 3 banners, two at the top and one on the side bar.

Now what I want to do is get the URL of the page, in this case and insert this into a database, so that the client who has the banner on my site knows that it was displayed at a given time (for example 10:00am, on a given date (for example 11/12/2003) and on this given URL (in this case
That is why I want to get the URL of the page where the banner is displayed.

Hope I am a bit more clear now
 
So I assume you build the querystring for the banners when they are clicked so just add to the end fo the path this
pathinfo=<%=request.servervariables(&quot;path_info&quot;)%>

e.g.

<a href=&quot;dbadd.asp?company=somecompany&pathinfo=<%=request.servervariables(&quot;path_info&quot;)%>&quot;>
<img src=bannerimage.jpg></a>

Then just request(&quot;pathinfo&quot;) for the name and path of the page where the banner was

 
No we are not on the same path!

Before the banners are clicked, they are displayed on a page right?

So

1) the banner is displayed on my page (for example
2) the user clicks on the banner

3) the user is taken to the website that pertains to that banner.

Now I know how to do Step 2 and Step 3, infact I am already populating the database with the URL from where the banner was clicked.

What I want to do is, in Step 1, when the banner is just displayed (and no clicks have been made as yet!), I want to retreive the URL on which that banner is displayed (before being clicked)
 

So why not update the database as the page is being created?

Surely you know the details of the banner before the page is sent?

 
Well request.servervariables(&quot;path_info&quot;) gives you the path name. To update the db you're going to need to call another page to insert this into the database by using javascript and revealing your db info to everyone, using a popup or moving to another page then redirecting to the banner's site.

 
Unless you're adding the site names for all banners on the page regardless whether they've been clicked in which case as I've told you us request.servervariables(&quot;path_info&quot;) to update the db with serverside asp code.

 
Hello Gary,

request.servervariables(&quot;path_info&quot;) just gives me a blank name, cause this does not work if the page is not redirected to another ASP. At this moment, I do not have to redirect to another page since I want the user that is viewing the banner on my site to stay on the same page, until he clicks on the banner, then he is redirected.
 
Well it shouldn't be blank, these are server variables that relate to the current page, you can also use
request.servervariables(&quot;script_name&quot;) for the page name only with no path info.

Try this, save as test.asp or something
<%
response.write request request.servervariables(&quot;path_info&quot;) & &quot;<BR>&quot;
response.write request request.servervariables(&quot;script_name&quot;)
%>

It will write out ...
somepath/test.asp ' if stored in a sub directory
test.asp

 
Wow

this worked on my work browser! I swear that on my home browser it was not working and just gave me a blank field.

Ok thanks Gary, then I will try this on my home browser and I hope to have the same results.

I will also check my code at home, maybe I was missing something.

Thansk very much and sorry for the hassle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top