views:

976

answers:

8

Basically what the title says...

I need to have an image that when clicked, I call script.php for instance and in that PHP script file, I get the image coordinates where the mouse was clicked.

Is this possible?

EDIT:
After a couple of answers I realized I didn't describe my problem correctly... The thing is, I don't have total control over the HTML. The control I have for the image and the image link is the control BBCode provides me.

Basically want I want to do is to have a forum signature with links to various sections on my website. You could argue I could use multiple images but most forums limit how much you can type for the signature, which is not enough for multiple images.

So, I will only be able to do something like this:

[url=http://www.mydomain.com/script.php]
[img]http://www.mydomain.com/signature.jpg[/img]
[/url]

Which translates to something like this:

<a href="http://www.mydomain.com/script.php"&gt;
<img src="http://www.mydomain.com/signature.jpg" />
</a>
+1  A: 

If you use an input type="image", which works like a button, it will send you x and y coordinates of the mouse click (submits form too).

More info here: http://www.htmlhelp.com/reference/html40/forms/input.html#image

Long time since I used it, but I did make it work for a "where's the ball?" competition on a site many years ago.

Update:

Sounds like the environment is just too limited to do what you want. If the forum lets you do an image map that would work, but I doubt they'd let you. Only other things I could think of would be flash or javascript, similarly, they prob won't allow them. You need something with a little more smarts than an image and an anchor to make this work.

seanb
I can't do that :( I just updated my post with more info on my problem.
Nazgulled
+2  A: 

if you set the image input name="foo", then $_POST['foo_x'] and $_POST['foo_y'] will be set to the image coordinates.

jmucchiello
I tried that for the <img> tag but it didn't work. But I suppose that your suggestion was something in the lines of seanb's answer? If so, the same info on my updated post also applies.
Nazgulled
BBCODE won't let you do what you want. There has to be a <FORM>. The image has to be an <INPUT type="image"> tag.
jmucchiello
A: 

You can use an ajax request when "onclick" is performed to send a request to "script.php". Otherwise I would read up on php, which is a server-side language.

Check my updated post, can't use ajax at all.
Nazgulled
A: 

This will not be possible unless you can add inline event handlers to the url in bbcode.

Joshua
+4  A: 

If you can't:

  1. use JavaScript, or
  2. use input type="image", or
  3. add any attributes to your img tag (to do things like create an image map)

then, no, you won't be able to do what you describe.

xyz
+1  A: 

You could try using W3C Image Maps

Image maps allow authors to specify regions of an image or object and assign a specific action to each region (e.g., retrieve a document, run a program, etc.) When the region is activated by the user, the action is executed.

But on a forum in BBCode, I really don't think you're going to be able to get what you're after.

Dean
A: 

Another solution, though not for BBCode is to use the ismap attribute for img. But may be valuable to others needing exact coordinates. Example:

<a href="link.html"><img src="shapes.jpg" alt="Shapes" ismap="ismap"/></a>

The x and y coordinates will be passed as GET parameters to link.html

recursive
A: 

I thought so :(

Well, thank you all anyway.

Nazgulled