/    Sign up×
Community /Pin to ProfileBookmark

Javascript – Creating Dynamic styles using CSS?

Hi I need to create a js program that prompts the user to enter a style between 4 choice into a dialog box. Depending on the style chosen the layout of the page itself will change. Say if the user chose type in red the screen will turn red. any assistance or examples would be great

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayApr 09.2009 — Easiest way is to set up separate style sheets and then do something like:

[code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function cssChng(val) {
alert(val);
document.getElementById("cssTag").href=val;
}
</script>
<link href="default.css" type="text/css" rel="stylesheet" id="cssTag" />

</head>

<body>
<select onchange="cssChng(this[this.selectedIndex].value)">
<option value="default.css">Default</option>
<option value="css1.css">First</option>
<option value="css2.css">Second</option>
</select>

</body>
</html>[/code]
Copy linkTweet thisAlerts:
@renegade420authorApr 09.2009 — Thanks

In this case I need a prompt box for the user to enter which style they like and I need for all css styles to be embedded in the head of the document.

I tried to find examples on google but havent found what I'm looking for.
Copy linkTweet thisAlerts:
@TheBearMayApr 09.2009 — You mean something like:

[code=html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function cssChng(val) {
document.getElementById("cssTag").href=val;
}
</script>
<link href="default.css" type="text/css" rel="stylesheet" id="cssTag" />

</head>

<body>
Enter Style Name
<input type="text" onchange="cssChg(this.value+'.css')" />

</body>
</html>[/code]
×

Success!

Help @renegade420 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 5.28,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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