Newbie Image question

R

Robert Hogan

Hello,

Hopefully a basic question.

I have an image that when someone clicks on it a want to execute a
process in which I use the co-ordinates (and store those co-oridnates
into a table).

The code displaying the image is

<a href="SetupMap.asp">
<img ismap src="/images/Map.bmp"
</a>

so when someone clicks it goes to the asp fine, (Eg.
..../SetupMap.asp?100,50). My question is how do I retrieve the passed
co-ordinates and place them in a variable? Since it's not a form the
usual methods (the ones I find documented) don't seem to apply.

Thanks in advance.
 
M

McKirahan

Robert Hogan said:
Hello,

Hopefully a basic question.

I have an image that when someone clicks on it a want to execute a
process in which I use the co-ordinates (and store those co-oridnates
into a table).

The code displaying the image is

<a href="SetupMap.asp">
<img ismap src="/images/Map.bmp"
</a>

so when someone clicks it goes to the asp fine, (Eg.
.../SetupMap.asp?100,50). My question is how do I retrieve the passed
co-ordinates and place them in a variable? Since it's not a form the
usual methods (the ones I find documented) don't seem to apply.

Thanks in advance.


Perhaps this will work for you:


<html>
<head>
<title>?</title>
<script type="text/javascript">
var x = 0;
var y = 0;
var z = "";
function goto(page) {
location.href = page+z;
}
function xy() {
x = window.event.screenX;
y = window.event.screenY;
z = x + "," + y;
}
</script>
</head>
<body>
<a href="javascript:goto('SetupMap.asp?')">
<img src="/images/Map.bmp" border="0" alt="" onclick="xy()">
</a>
</body>
</html>


Watch for word-wrap. Also, you should specify the width and height of the
image.
 
M

Michael Winter

[snip]
so when someone clicks it goes to the asp fine, (Eg.
.../SetupMap.asp?100,50). My question is how do I retrieve the passed
co-ordinates and place them in a variable? Since it's not a form the
usual methods (the ones I find documented) don't seem to apply.

You can retrieve the "query string" (everything after the question mark
(?) in a URI) using the Location.search property. For example:

var coordinates = window.location.search.substr( 1 ).split( ',' );

That will trim the question mark and create an array that contains the x
and y co-ordinates (as strings, not numbers) in the first and second
elements, respectively. That is,

var x = coordinates[ 0 ];
var y = coordinates[ 1 ];

Mike
 
M

McKirahan

Ooops, I didn't read your post very well; you asked how to "retrieve" not
"pass" coordinates...

I like Michael Winter's solution for parsing a querystring.
 
E

Evertjan.

Robert Hogan wrote on 30 jan 2004 in comp.lang.javascript:
so when someone clicks it goes to the asp fine, (Eg.
.../SetupMap.asp?100,50). My question is how do I retrieve the passed
co-ordinates and place them in a variable? Since it's not a form the
usual methods (the ones I find documented) don't seem to apply.

In the file SetupMap.asp do (serverside VBS):

<%
q = split(request.querystring,",")
x = q(0)
y = q(1)
%>

not tested
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top