473,624 Members | 2,502 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to define a global variable in HTML file?


Hello Group,

Does anybody know how I can have a global variable in an HTML file? for
instance, I have a fuction (called aFunction() here) and during a
mousedown or up event the function is going to be called.

The third passing arugment or parameter is myGlobarVar. How can I make
this work? since myGlobalVar is defined in a different block of
javascript within the HTML file?
<html>

<head>

<title>testin g an HTML for global variable!</title>

<script type="text/javascript" src="myfile.js" >
var myGlobalVar = "S100";
aFunction();
</script>

</head<body>

My IMAGE
<img onmousedown= "javascript:aFu nction(ev, this, myGlobalVar);"
onmouseup="java script:aFunctio n(ev,this);" src="MyImage.gi f" border=0
>
</body>

</html>
Thanks in advance.
Amit.

Jul 21 '06 #1
1 24165

amit wrote:
Hello Group,

Does anybody know how I can have a global variable in an HTML file? for
instance, I have a fuction (called aFunction() here) and during a
mousedown or up event the function is going to be called.

The third passing arugment or parameter is myGlobarVar. How can I make
this work? since myGlobalVar is defined in a different block of
javascript within the HTML file?
<html>

<head>

<title>testin g an HTML for global variable!</title>

<script type="text/javascript" src="myfile.js" >
var myGlobalVar = "S100";
aFunction();
</script>

</head<body>

My IMAGE
<img onmousedown= "javascript:aFu nction(ev, this, myGlobalVar);"
onmouseup="java script:aFunctio n(ev,this);" src="MyImage.gi f" border=0

</body>

</html>
Thanks in advance.
Amit.

Now it is working! my problem was that I was mixing the include
javascript file statement and the variable together in one single
block. When I separate them it works just fine. Thanks anyway.

wrong way:

<script type="text/javascript" src="myfile.js" >
var myGlobalVar = "S100";
aFunction();
</script>
corrected:

<script type="text/javascript" src="myfile.js" >
</script>

<script type="text/javascript" src="myfile.js" >
var myGlobalVar = "S100";
</script>

Jul 21 '06 #2

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

Similar topics

12
5868
by: David WOO | last post by:
Hi, I am a newbie on C++, I need to define some global variables which should be accessible to most classes. In the mean time, I don't won't the global variables be modified freely at most of these classes. I know there is a pattern called singleton can more or less do such a trick. I am wondering is this the best way to do it (regarding the convenience and safety), as this is such a fundamental thing, I believe most of you have a say...
2
5180
by: Bryan Parkoff | last post by:
….I would like to know which is the best optimization to use global variable or global struct. I always tell C/C++ Compiler to turn on optimization. ….I use underscore between first name and second name for better readable. After optimization, global variables might be misaligned because each global variables must be converted to 32 bits, but I do see that C/C++ Compiler do padding between variables. Struct does the same to do padding....
17
12277
by: Davor | last post by:
How to define global variable in main()? I'm asking because I have an array in main, whose size is determined by input, so the definition has to be in main ( or in some other funcion ). And I need to use that array in my other functions, so I want it to be global. I tryed using extern keyword, but I gut some error, so I supose that's not it. thanks in advance Davor :-)
10
387
by: Simon Harvey | last post by:
Hi everyone, Can anyone tell me if I declare a global variable in my pages code behind, is it persisted if the page does a post back, or do I need to add the object to the session object in order to persist it. Is the session the best mechnism for persisiting this object Thanks everyone
2
4298
by: Tark Siala | last post by:
hi i worked with VB6 then i changed to C#. i want define Variable thats i can accessed from any Form or Class in my project. in VB6 you can do that by define as "Global" in Module, but in C# i can't find Global for all forms in project. ----------- Tarek M. Siala Software Developer http://tarksiala.blogspot.com
0
8246
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
8179
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,...
0
8631
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7174
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
6112
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
5570
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
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.