473,749 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need a "static" variable for using window.event.cl ientX

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.cl ientX 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.cl ientX. 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.cl ientX and
window.event.cl ientY 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.cl ientX;
HelpY = window.event.cl ientY;
ToShow = setTimeout( "DoRollOver ()", 1, "JAVASCRIPT " );
}

// This is the HTML
<input type="Text" name="timestamp 1" value="">
<img src="myImage.gi f" onmousedown="Ro llOver( 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 5212
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.cl ientX;

if( HelpY == 0 )
HelpY = window.event.cl ientY;

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

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

Oct 20 '05 #2
ch***********@g mail.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***********@g mail.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.cl ientX;
You can simplify the test, and make this cross-browser (see below).

if( HelpY == 0 )
HelpY = window.event.cl ientY;
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(func tion(){
showRollOver(He lpXY[0], HelpXY[1], txt);
}, 500);
}
}

function showRollOver(x, y, t)
{
var oDiv = document.create Element('div');
oDiv.style.posi tion = 'absolute';
oDiv.style.left = x + 'px';
oDiv.style.top = y + 'px';
oDiv.style.back groundColor = '#eeeeee';
document.body.a ppendChild(oDiv )
oDiv.innerHTML = t;
setTimeout(func tion() {deleteHelp(oDi v)}, 2000);

}

function deleteHelp(el)
{
el.parentNode.r emoveChild(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.s crollLeft,
e.clientY + document.body.s crollTop];
}
}
</script>

<img src="a.jpg" onmousedown="Ro llOver(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
2213
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 I have initialised (right word?) it like this int exClass::nextFree; Now below is a code fragment from a non-static function in another class (exClass.h was included at the top of the .cpp file).
4
1992
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
2310
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 that the app uses. So I will need to change the fonts depending on what settings the user has entered. However, it seems kind of wasteful to me to go to teh registry, fetch the font information and create new font objects for every form that I am...
10
2906
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 SomeClass { public SomeClass() { abc++; // Instance Variable xyz++; // Static Variable
0
1110
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 __events. In short, every new instance of the class clears all existing listening registered delegates. It should, of course, preserve all delegates since its static, but it does not according to this: "The real problem is the instance constructor...
11
2156
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) { if (is_dir("$baseDir/$fyl")) blah($item);
6
2394
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 running on IIS 5/6 that interfaces with a 3rd party DLL referenced by using the DLLImport attribute. Interacting with this 3rd party software through this dll requires an
14
6023
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 static inside functions (i.e. local static objects) 5. objects declared at file scope.
37
5475
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 are the one which runs statically with the defining class. Hence, my understanding is that static variables must be bound to the class defining the variables and shared by children of parent class where the variable is defined. But, please have a...
11
8330
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 device_t { const device_backend_t *backend; ... } device_t; typedef struct device_backend_t {
0
8997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.