Im trying to capture every X and Y Co-ordinate of a page.
Is there some kind of function of special tag that I culd learn so that when I run my mouse over any section of a page, an X and Y co-ordinate is given??
just copy the code and paste it between <script> tags... either of these will work, but you may want to use mine because the variables are all local to the function... jared@aauser.com
If you use Netscape you have to use pageX(Y) instead of clientX(Y)
Comment: With IE clientX/Y gives you the coordinates as Screen Coordinates. if you would use offsetX/Y it would return the Coordinates relativ to the Object.
Allow a user to place an image or text anywhere on the page.
I can do this via capturing an X and Y co-ordiante via a form, passing the variable to a action page, and then using CSS and Coldfusion to use the variables to place the text/image according to the co-ordinate. This is rimitive but it works
However, the user needs to be able to visually see where they want to place the image or text on the input page, therefore I was thinking a series of checkboxes where a user can choose two checkboxes (to represent an X and Y Co-ordinate). This is then captured and displayed on the actionpage accordingly.
I dont think ive explained it very well, If a more detailed explanantion is required, then please let me know.
i am attaching my code to help clarify what I'm trying to do:
Createpage.cfm (this is the page where the users X'Y's co-ordinate is captured, but at the moment, the user is entering the co-ordinates blindly i.e. unsure what the co-ordinate (100,100) will yield)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Enter your X Co-ordinate <INPUT TYPE ="Text" NAME="X"><BR>
Enter your Y Co-ordinate <INPUT TYPE ="Text" NAME="Y"><BR>
<INPUT TYPE = "Submit" VALUE ="Enter">
<INPUT TYPE = "Reset" VALUE ="Clear">
</FORM>
</body>
</html>
This is the actionpage where the variables are retrieved and positioned accordingly:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<body>
<script>
function mouseMoved()
{
var eobj,thex,they
eobj = window.event
if(eobj.srcElement.className=="clickablearea"
{
thex = eobj.clientX
they = eobj.clientY
document.formname.x.value=thex
document.formname.y.value=they
}
}
document.onclick=mouseMoved
</script>
<div class="clickablearea">Ma701sd, you can store these coords.</div><br><br>
<div>But not these...</div>
<form name="formname">
<input name=x><input name=y>
</form> jared@aauser.com
I was trawling through my emails and I found the reply for this post I put up ages ago!
Thanks for your replys
I tried it and it works although it's not exactly how I want it to work however you have provided the mechanics of what I need.
Can ask a favour, Could you possibly provide some coments (in real layman terms) as i've never done javascript before?
Also I modifed what you did to make it fit with what I'm doing, but I get a runtime error and asks would I like to debug? WHy does it do this, heres the code:
<style>
.clickablearea{cursor:hand;}
</style>
</head>
<body>
<script>
function mouseMoved()
{
var eobj,thex,they
eobj = window.event
if(eobj.srcElement.className=="clickablearea"
{
thex = eobj.clientX
they = eobj.clientY
document.formname.x.value=thex
document.formname.y.value=they
}
}
document.onclick=mouseMoved
</script>
<div class="clickablearea">Ma701sd, you can store these coords.</div><br><br>
<div>But not these...</div>
<!--- <form name="formname"> --->
<!--- <input name=x><input name=y> --->
Enter your X Co-ordinate <INPUT NAME=X><BR>
Enter your Y Co-ordinate <INPUT NAME=Y><BR>
<INPUT TYPE = "Submit" VALUE ="Enter">
<INPUT TYPE = "Reset" VALUE ="Clear">
</FORM>
</body>
</html>
Once Ive obtained the co-ordinate, I want to pass it to the next page for which I have have the code to manipulate..Is this correct in terms of the logisitics:
function mouseMoved()
{
var eobj,thex,they
eobj = window.event
//store the event object
if(eobj.srcElement.className=="clickablearea"//check to see if its "clickable"
{
thex = eobj.clientX //store y coord
they = eobj.clientY //store x coord
//display them
document.formname.x.value=thex
document.formname.y.value=they
}
}
document.onclick=mouseMoved
//every time the mouse moves call mouseMoved jared@aauser.com
Thanx for your help.
Sorry to keep this going...
But..
Is it possible to extend the range of the "clickable area" e.g. make half the page or the whole page clickable?
Hi Jaredn,
Sorry, but I have another question that I hope you might be able to help me with..
WHat I have done is embedded the code within two forms (Eventually I want to make as many forms as there are elements that I want to position). WHat I have done is made the clickable area a table row, but, As I have two forms and I click on the top row, the co-ordinates are displayed in the second forms input box. I hope this makes sense...I have posted the code..Please help
The X Co-Ordinate is <input type="text" name="x" Value=0><BR>
The Y Co-Ordinate is <input type="text" name="y" Value=0>
<INPUT TYPE = "Submit" VALUE ="Enter">
<INPUT TYPE = "Reset" VALUE ="Clear">
I tried the second option i.e remove the
if(eobj.srcElement.className=="clickablearea"
but what happens now is that when I submit to the action page by clicking "enter" button, the co-ordinates of the "enter" button are captured every time...
Is there anyway to stop this from happening?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.