By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,968 Members | 1,458 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,968 IT Pros & Developers. It's quick & easy.

How to define a global variable in HTML file?

P: n/a

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
Share this Question
Share on Google+
1 Reply


P: n/a

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 discussion thread is closed

Replies have been disabled for this discussion.