\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Other Languages > Web Programming > Javascript: Get position of click in HTML


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\r\n
Ref: XHTML / Javascript: Advanced text editor
\r\n
\r\nHi. Ive spent all night working on this and im starting to get a basic idea of what to do so now i have a more specific question.
\r\n
\r\nWhen i click on the div that im using to represent a textbox i get the X and Y position of the click
\r\n
\r\n
Code:
\r\n
function getXPos(e){\r\n    return e.pageX || (e.clientX+(document.documentElement.scrollLeft || document.body.scrollLeft));\r\n}\r\nfunction getYPos(e){\r\n    return e.pageY || (e.clientY+(document.documentElement.scrollTop || document.body.scrollTop));\r\n}\r\nfunction editor_onClick(e){\r\n\r\n    var editor=SPKGetObject(\'editor\');\r\n\r\n    clickX=getXPos(e)-editor.offsetLeft;\r\n    clickY=getYPos(e)-editor.offsetTop;\r\n}
\r\n
How do i detect which span was clicked in? Would it make more sense to attach an event to every span or can it be done by looping through each span in the div?
\r\n
\r\nI plan to have every bit of text inside a span but not have any span inside another span
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n
\r\n __________________
\r\n "That which seems simple is often overlooked" ~ me
\r\nHalloween Special FX
\r\nWeb Hosting from Spook Technologies\r\n
\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; // next/previous post info pn[1278751] = "1278751,1278751"; pn[0] = ",1278751"; // cached usernames pu[0] = guestphrase; pu[31631] = "the master"; // -->
Prev Previous Post   Next Post Next
  #1  
Old 03-15-2008, 06:56 AM
the master's Avatar
the master the master is offline
Tachikoma
 
Join Date: Mar 2003
Location: Mansfield, UK
Posts: 4,594
Default Javascript: Get position of click in HTML


Ref: XHTML / Javascript: Advanced text editor

Hi. Ive spent all night working on this and im starting to get a basic idea of what to do so now i have a more specific question.

When i click on the div that im using to represent a textbox i get the X and Y position of the click
Code:
function getXPos(e){
    return e.pageX || (e.clientX+(document.documentElement.scrollLeft || document.body.scrollLeft));
}
function getYPos(e){
    return e.pageY || (e.clientY+(document.documentElement.scrollTop || document.body.scrollTop));
}
function editor_onClick(e){

    var editor=SPKGetObject('editor');

    clickX=getXPos(e)-editor.offsetLeft;
    clickY=getYPos(e)-editor.offsetTop;
}
How do i detect which span was clicked in? Would it make more sense to attach an event to every span or can it be done by looping through each span in the div?

I plan to have every bit of text inside a span but not have any span inside another span
__________________
"That which seems simple is often overlooked" ~ me
Halloween Special FX
Web Hosting from Spook Technologies
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->