473,386 Members | 1,766 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,386 software developers and data experts.

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>testing 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:aFunction(ev, this, myGlobalVar);"
onmouseup="javascript:aFunction(ev,this);" src="MyImage.gif" border=0
>
</body>

</html>
Thanks in advance.
Amit.

Jul 21 '06 #1
1 24118

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>testing 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:aFunction(ev, this, myGlobalVar);"
onmouseup="javascript:aFunction(ev,this);" src="MyImage.gif" 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
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...
2
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...
17
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...
10
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.