473,320 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Need a "static" variable for using window.event.clientX

Hi everyone,

I didn't know how to sum this up very well for the title, but hopefully
the person(s) will come along who can help.

I'm trying to use the window.event.clientX value for positioning a
javascript routine, but I'm having trouble. When the javascript
routine comes up, it comes up in a certain position based on
window.event.clientX. However, the user could click on something in
the script display (say, like a menu, or a calendar, or something),
that my "refresh" (reload that same script but with different values).
Thus, the first time, it works perfectly, but thereafter, it sets the
new x,y values to the most recent window.event.clientX and
window.event.clientY positions. I want it ONLY USE the positions which
were first used.

Does this make sense? Ok, here is the code snippets:

// This is the javascript
function RollOver( Text )
{
HelpText = Text ;
HelpX = window.event.clientX;
HelpY = window.event.clientY;
ToShow = setTimeout( "DoRollOver()", 1, "JAVASCRIPT" );
}

// This is the HTML
<input type="Text" name="timestamp1" value="">
<img src="myImage.gif" onmousedown="RollOver( getText() );">
The first time the image is clicked, the source comes up in the correct
place. But this new script that came up is now the current "event" so
when someone clicks on something to reload the script with a different
value, it sets the position relative to the lastest script placement,
not the original image.

If this doesn't make sense, let me know. Any help is greatly
appreciated!!!

Oct 20 '05 #1
5 5165
Nevermind, I found something that will work. This is what I did:

<script ...>
var HelpX = HelpY = 0 ;

function RollOver( Text )
{
HelpText = Text ;

if( HelpX == 0 )
HelpX = window.event.clientX;

if( HelpY == 0 )
HelpY = window.event.clientY;

ToShow = setTimeout( "DoRollOver()", 1, "JAVASCRIPT" );
}

Thanks, anyway. Hopefully this will help someone else out!

Oct 20 '05 #2
ch***********@gmail.com wrote:
ToShow = setTimeout( "DoRollOver()", 1, "JAVASCRIPT" );


What's the use of the third argument? AFAIK, the setTimeout function
excepts only two...
JW

Oct 20 '05 #3
Janwillem Borleffs wrote:
What's the use of the third argument? AFAIK, the setTimeout function
excepts only two...


Never mind, appears to be an IE thingy...
JW
Oct 20 '05 #4
I'm getting the following error:
getText is not defined
What gives?
Thanks
JM

Oct 21 '05 #5
Zif
ch***********@gmail.com wrote:
Nevermind, I found something that will work. This is what I did:

<script ...>
var HelpX = HelpY = 0 ;

function RollOver( Text )
{
HelpText = Text ;

if( HelpX == 0 )
HelpX = window.event.clientX;
You can simplify the test, and make this cross-browser (see below).

if( HelpY == 0 )
HelpY = window.event.clientY;
If HelpX was not defined, then neither will HelpY be, so if not one, do
both. And use a cross-browser method of finding the location of the event:

if (!HelpX) {
var pos = getPos(e);
HelpX = pos[0];
HelpY = pos[1];

ToShow = setTimeout( "DoRollOver()", 1, "JAVASCRIPT" );
What is the point of using setTimeout with a delay of 1ms? It will
appear instantaneous.
}

Thanks, anyway. Hopefully this will help someone else out!

Only if intended for IE. Cross-browser version (tested in IE an Firefox):
<script type="text/javascript">

var HelpXY;
var onShow;

// Dummy getText function
function getText(){ return 'the Help text'; }

function RollOver(e, txt)
{
var e = e || window.event;
if (!HelpXY {
HelpXY = getPos(e);
}
if (!onShow){
onShow = setTimeout(function(){
showRollOver(HelpXY[0], HelpXY[1], txt);
}, 500);
}
}

function showRollOver(x, y, t)
{
var oDiv = document.createElement('div');
oDiv.style.position = 'absolute';
oDiv.style.left = x + 'px';
oDiv.style.top = y + 'px';
oDiv.style.backgroundColor = '#eeeeee';
document.body.appendChild(oDiv)
oDiv.innerHTML = t;
setTimeout(function() {deleteHelp(oDiv)}, 2000);

}

function deleteHelp(el)
{
el.parentNode.removeChild(el);
onShow = null;
// Comment out next line to have text always appear
// where first click was
HelpXY = null;
}

// Get the mouse position (adapted from quirksmode)
function getPos(e)
{
if (e.pageX || e.pageY){
return [ e.pageX, e.pageY];
} else if (e.clientX || e.clientY) {
return [ e.clientX + document.body.scrollLeft,
e.clientY + document.body.scrollTop];
}
}
</script>

<img src="a.jpg" onmousedown="RollOver(event, getText() );">

--
Zif
Oct 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Connell Gauld | last post by:
Hi, I'm using VC++. I have a class called exClass defined in exClass.h exClass has a static variable, declared like this in the public section. static int exStaticVar; Below the class definition...
4
by: santosh | last post by:
Hello, I have a doubt about static variable. class B { private: static int x; public: static set(int y) {
9
by: Neil Kiser | last post by:
I'm trying to understand what defining a class as 'static' does for me. Here's an example, because maybe I am thinking about this all wrong: My app will allows the user to control the fonts...
10
by: Rene | last post by:
I jus realized that I can change the values of "static variables" and "instance variable" through the standard constructor This means that something like this will compile: public class...
0
by: Dave L | last post by:
I just upgraded from VS .NET 2002 to 2003. Everything built okay, but strange bugs started appearing. Apparently there is a bug in the managed C++ compiler in regards to handling of static...
11
by: comp.lang.php | last post by:
function blah($item) { if (!isset($baseDir)) { static $baseDir = ''; $baseDir = $item; print_r("baseDir = $baseDir\n"); } $dirID = opendir($item); while (($fyl = readdir($dirID)) !== false)...
6
by: depalau | last post by:
I'm running into some issues on maintaining a static variable across the lifetime of a web service and I was wondering if anyone could help. Background: We have developed a C#/1.1 web service...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.