Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > problems with get cursor position

Reply
Thread Tools

problems with get cursor position

 
 
ton
Guest
Posts: n/a
 
      08-21-2008
Hi
I'm using this function:

function getPosition(e) {
e = e || window.event;
curs = {x:0, y:0};
if (e.pageX || e.pageY)
{curs.x = e.pageX;
curs.y = e.pageY; }
else
{curs.x = e.clientX +(document.documentElement.scrollLeft ||
document.body.scrollLeft) - document.documentElement.clientLeft;
curs.y = e.clientY +(document.documentElement.scrollTop ||
document.body.scrollTop) - document.documentElement.clientTop;}
}

when called in a function which was activited by:
"ondblclick" = "fAfspraak(" & ID & ");" the cursor values are calculted

but when called
.InnerHtml = "<a tabindex='1' href=fAfspraak(" & ID & ")' >" & text &
"</a>"

i receive a javascript error object requiered: there is no windows.event
(the function fAfspraak is called)

What is wrong here ?

thanx

ton

 
Reply With Quote
 
 
 
 
Anthony Jones
Guest
Posts: n/a
 
      08-21-2008
"ton" <(E-Mail Removed)> wrote in message
news:d05ce$48ad4866$541ef063$(E-Mail Removed)1.nb .home.nl...
> Hi
> I'm using this function:
>
> function getPosition(e) {
> e = e || window.event;
> curs = {x:0, y:0};
> if (e.pageX || e.pageY)
> {curs.x = e.pageX;
> curs.y = e.pageY; }
> else
> {curs.x = e.clientX +(document.documentElement.scrollLeft ||
> document.body.scrollLeft) - document.documentElement.clientLeft;
> curs.y = e.clientY +(document.documentElement.scrollTop ||
> document.body.scrollTop) - document.documentElement.clientTop;}
> }
>
> when called in a function which was activited by:
> "ondblclick" = "fAfspraak(" & ID & ");" the cursor values are calculted
>
> but when called
> .InnerHtml = "<a tabindex='1' href=fAfspraak(" & ID & ")' >" & text &
> "</a>"
>
> i receive a javascript error object requiered: there is no windows.event
> (the function fAfspraak is called)
>
> What is wrong here ?
>


There is no event in progress when that code runs. Try:-

"<a href=""javascript:void(0)"" onclick=""fAfspraak(" & ID & ")"""

BTW it looks like the code is expecting to be cross browser, how do you
intend to get a Mozilla event object into the getPosition function?

My preference is:-

<a href="javascript:void(0)" onclick="myFunc.apply(this, arguments)"
myID="12345">Click me</a>

Then in myFunc:-

function myFunc(e)
{
var id = this.getAttribute("myID")
var pos = getPosition(e)

// rest of your code

}

If you have dozens of these in a list consider:-

<div onclick="myFunc.apply(this, arguments)">
<a href="javascript:void(0)" myID="12345">Click me</a>
<a href="javascript:void(0)" myID="12346">No Click me</a>
</div>

The myFunc becomes:-

function myFunc(e)
{
var elem = e ? e.target : window.event.srcElement
var id = elem.getAttribute("myID")
var pos = getPosition(e)

// rest of your code
}

The generated html is smaller, the cost of event wire up (which can be
significant) is reduced, and your generating code looks cleaner especially
if you choose String.Format over the contentation you are currently doing.



--
Anthony Jones - MVP ASP/ASP.NET


 
Reply With Quote
 
 
 
 
ton
Guest
Posts: n/a
 
      08-21-2008
WOUW !!!!

thnx anthony

ton

"Anthony Jones" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> "ton" <(E-Mail Removed)> wrote in message
> news:d05ce$48ad4866$541ef063$(E-Mail Removed)1.nb .home.nl...
>> Hi
>> I'm using this function:
>>
>> function getPosition(e) {
>> e = e || window.event;
>> curs = {x:0, y:0};
>> if (e.pageX || e.pageY)
>> {curs.x = e.pageX;
>> curs.y = e.pageY; }
>> else
>> {curs.x = e.clientX +(document.documentElement.scrollLeft ||
>> document.body.scrollLeft) - document.documentElement.clientLeft;
>> curs.y = e.clientY +(document.documentElement.scrollTop ||
>> document.body.scrollTop) - document.documentElement.clientTop;}
>> }
>>
>> when called in a function which was activited by:
>> "ondblclick" = "fAfspraak(" & ID & ");" the cursor values are
>> calculted
>>
>> but when called
>> .InnerHtml = "<a tabindex='1' href=fAfspraak(" & ID & ")' >" & text &
>> "</a>"
>>
>> i receive a javascript error object requiered: there is no windows.event
>> (the function fAfspraak is called)
>>
>> What is wrong here ?
>>

>
> There is no event in progress when that code runs. Try:-
>
> "<a href=""javascript:void(0)"" onclick=""fAfspraak(" & ID & ")"""
>
> BTW it looks like the code is expecting to be cross browser, how do you
> intend to get a Mozilla event object into the getPosition function?
>
> My preference is:-
>
> <a href="javascript:void(0)" onclick="myFunc.apply(this, arguments)"
> myID="12345">Click me</a>
>
> Then in myFunc:-
>
> function myFunc(e)
> {
> var id = this.getAttribute("myID")
> var pos = getPosition(e)
>
> // rest of your code
>
> }
>
> If you have dozens of these in a list consider:-
>
> <div onclick="myFunc.apply(this, arguments)">
> <a href="javascript:void(0)" myID="12345">Click me</a>
> <a href="javascript:void(0)" myID="12346">No Click me</a>
> </div>
>
> The myFunc becomes:-
>
> function myFunc(e)
> {
> var elem = e ? e.target : window.event.srcElement
> var id = elem.getAttribute("myID")
> var pos = getPosition(e)
>
> // rest of your code
> }
>
> The generated html is smaller, the cost of event wire up (which can be
> significant) is reduced, and your generating code looks cleaner especially
> if you choose String.Format over the contentation you are currently doing.
>
>
>
> --
> Anthony Jones - MVP ASP/ASP.NET
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to tell if cursor is sqlite.Cursor or psycopg2.Cursor dmaziuk Python 3 01-25-2011 04:52 AM
Re: Tkinter.Text widget - how to get text cursor position? Alex9968 Python 0 03-19-2008 07:07 PM
Tkinter.Text widget - how to get text cursor position? Alex9968 Python 0 03-19-2008 05:37 PM
How to get cursor insertion point (caret position) from text box DaveR ASP .Net 2 11-17-2004 09:39 AM
Get/Set Cursor Position in Form Textarea? Peer W Hansen HTML 0 05-16-2004 04:37 PM



Advertisments