/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Really global variable definition?

Is there a proper syntax that would allow a global variable assignment
to be accessed by JS and CSS and HTML?

This doesn’t work, but I’m looking to see if it’s possible.

[code=php]
<html>
<head>
<title>Global variable</title>

var CWIDE = 100; // want access to JS, CSS and HTML
var CHIGH = 100; // desire to set once and effect definitions below

<script type=”text/javascript”>
function Defaults() {
CWIDE = 100;
CHIGH = 100;
}
function LargerDefaults() {
CWIDE = 200;
CHIGH = 200;
}
function SmallerDefaults() {
CWIDE = 50;
CHIGH = 50;
}
</script>
<style type=”text/css”>
#IMGdiv {
height:CHIGH;
wide:CWIDE;
}
</style>
</head>
<body>
<div id=”IMGdiv”>
<img id=”shownIMG” src=”Picture.gif” height=CHIGH width=CWIDE>
</div>
<button onClick=”Defaults()”>Default Size</button>
<button onClick=”LargerDefaults()”>Enlarge Size</button>
<button onClick=”SmallerDefaults()”>Reduce Size</button>
</body>
</html>
[/code]

I would like to set or change the first CWIDE / CHIGH values (somehow???)
and have them effect the rest of the scripts.

Is there a way to do this?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangNov 24.2007 — Do it with a server side language or define a [I]class[/I] for each default.
Copy linkTweet thisAlerts:
@JMRKERauthorNov 24.2007 — Thanks for the information.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...