Forum Moderators: open
I was curious how I can create a javascript that I declare variables in and then look to an external script to use these variables.
So basically... I declare the variables in the html file
<script">
var width = 330
var height = 306
</script>
And then call the javascript that uses the file which contains...
<script language="JavaScript">
document.write("Height=" + height + " Width=" + width);
</script>
Hopefully that made sense. :)
Wes
What you need to do is firstly declare te variables like you have before.
<script>
var myWidth = 330
var myHeight = 306
</script>
And then include the external JS file as follows:
<script src="external-file.js"></script>
And then you can use the variables in the "external-file.js" like so:
alert("Height=" + myHeight + " Width=" + myWidth);
I hope this helps.