Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Thu, 21 Aug 2008 12:50:17 +0200,    group: microsoft.public.dotnet.framework.aspnet        back       


problems with get cursor position   
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
date: Thu, 21 Aug 2008 12:50:17 +0200   author:   ton

Re: problems with get cursor position   
"ton"  wrote in message
news:d05ce$48ad4866$541ef063$5459@cache2.tilbu1.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
date: Thu, 21 Aug 2008 14:10:05 +0100   author:   Anthony Jones

Re: problems with get cursor position   
WOUW !!!!

thnx anthony

ton

"Anthony Jones"  schreef in bericht 
news:%23Tlr784AJHA.3752@TK2MSFTNGP03.phx.gbl...
> "ton"  wrote in message
> news:d05ce$48ad4866$541ef063$5459@cache2.tilbu1.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
>
>
date: Thu, 21 Aug 2008 15:58:01 +0200   author:   ton

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us