Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:28:59+00:00 2026-06-13T06:28:59+00:00

What I am trying to do should be easy for a Js guy, but

  • 0

What I am trying to do should be easy for a Js guy, but I am just a php guy (just a starter.). I need this for a project that I am doing now.

What I am trying to do is, get the click co-ordinates over the image and post it to a php script so that I can get the values and do the rest of the processing. (I dont know ajax, so this is the only way I can do that I suppose).

I found a code, but this shows the X and Y points as many times as I need. I want it to work just for one time.

    <script type="text/javascript">
<!--

function FindPosition(oElement)
{
if(typeof( oElement.offsetParent ) != "undefined")
{
for(var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent)
{
posX += oElement.offsetLeft;
posY += oElement.offsetTop;
}
return [ posX, posY ];
}
else
{
return [ oElement.x, oElement.y ];
}
}

function GetCoordinates(e)
{
var PosX = 0;
var PosY = 0;
var ImgPos;
ImgPos = FindPosition(myImg);
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
PosX = e.pageX;
PosY = e.pageY;
}
else if (e.clientX || e.clientY)
{
PosX = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
PosY = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
PosX = PosX - ImgPos[0];
PosY = PosY - ImgPos[1];
document.getElementById("x").innerHTML = PosX;
document.getElementById("y").innerHTML = PosY;
}

//-->
</script>
<img src="newapp.jpg" alt="" id="myImgId" height="300" width="400"><p>Click on the image to get the coordinates.</p>


<script type="text/javascript">
<!--
var myImg = document.getElementById("myImgId");
myImg.onmousedown = GetCoordinates;
//-->
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:29:00+00:00Added an answer on June 13, 2026 at 6:29 am

    You can even do it without javascript (just with html and php 😉

    <?php
      $foo_x=$_POST['foo_x'];
      $foo_y=$_POST['foo_y'];
      echo "X=$foo_x, Y=$foo_y ";
    ?>
    <form action='' method=post>
      <input type="image" alt=' Finding coordinates of an image' src="xy-coordinates.jpg" name="foo" style=cursor:crosshair;/>
    </form>
    

    The key is the type-attribute set to type="image".

    Source and Demo: http://www.plus2net.com/php_tutorial/php_image_coordinates.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do something that seems like it should be easy but I'm
I know this should be easy but it's just not my day today. I
I am sure this should be easy but I ahve been going crazy trying
I'm trying something that should be pretty easy but i can't figure out how
This seems like it should be easy, but I can't get the right syntax.
This should be easy, but I'm stuck trying to modify this build.xml I'm getting
I'm trying to develop a component that should look somewhat like this I'm using
Okay so this query should be easy but I'm having a bit of difficult.
This seems like it should be easy as pie, but I can't seem to
I'm trying to get IE9 to display a custom font. Should be easy... researched

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.