/    Sign up×
Community /Pin to ProfileBookmark

Help Needed (maybe PHP would be better)

(NOTE: This was posted here because a good PHP might be preferred over a JS repair. I’m quite new to PHP and would thus need implentation guidance as well.)

===========================================

Hello All,

I have a script (JS) running a CSS style modifier (swaps to alternate CSS file) but it’s only working (flawlessly) on [i]MSIE[/i] and [i]Opera[/i] and it [b]doesn’t work[/b] on [i]FireFox[/i] or [i]Netscape[/i] at all. Moreover, the cookie isn’t being properly set either so if the [i]Styles Menu[/i] is used on those browsers, it still doesn’t hold the preference and thus won’t keep the style throughout navigation or upon return.

If anyone knows how to fix this script, or better yet, has a cool PHP script to do the same (and how to apply it) that would be most appreciated.

To aid you in viewing all relevant files, I have created a [url=http://www.gbhx.net/gbdc_www/cry_for_help.txt]text (*.txt) document with all the script and link info[/url].

In advance, thanks. ?

&gb;

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 02.2005 — You can do something [url=http://www.charles-reace.com/test/style/styles.php]like this[/url], perhaps.

The HTML with embedded PHP:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
<?php
# set style:
$style = (isset($_POST['style'])) ? $_POST['style'] : "style1.css";
echo "<link rel='stylesheet' href='$style'>n";
?>
<title>Multi Style</title>
<style type="text/css">
</style>
</head>
<body>
<div>
<?php
echo "<form action='{$_SERVER['PHP_SELF']}' method=post>n";
?>
<fieldset>
<legend>Choose page style</legend>
<p style="float: right"><input type=submit value="Submit"></p>
<p><label>Style 1:<input type=radio name=style value="style1.css" checked></label></p>
<p><label>Style 2:<input type=radio name=style value="style2.css"></label></p>
<p><label>Style 3:<input type=radio name=style value="style3.css"></label></p>
</fieldset>
</form>
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@Green-BeastauthorFeb 02.2005 — Thank you very much for that. I checked out your page as well (and it works on Firefox ?). It leads me to some questions to which I'm hoping there are some easy answers to:

1) Your page seems to have some odd thing going on. After cycling through the options I can't seem to get back to the default and if I click radio button 2 it reverts to button 1, so if i submit 1 then it takes me to style 2 (but maybe I'm confused). If the style number/name showed on it the style (as part of the background as an image) I'd be less confused.

2) I picked one style, number 3 I think (black and green), but when I went back to the site it was set to the default. In other words if it was multiple pages it'd revert to the "default" style upon load thus having to select a style on every page. It didn't or doesn't use a cookie, and that's part of what I need to pull off my project. So, can I get some cookie help too if possible.

I am pretty new to scripting so please bear with me. Thanks.
Copy linkTweet thisAlerts:
@NogDogFeb 02.2005 — For it to "remember" you would need to set/read a "cookie", which PHP can do just fine. I'm just too lazy to put that in for a sample script. ?

I did change it so that the current style is the selected radio button:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>
<?php
# set style:
if(! isset($_POST['style']))
{
$_POST['style'] = "style1.css";
}
$style = $_POST['style'];
echo "<link rel='stylesheet' href='$style'>n";
?>
<title>Multi Style</title>
<style type="text/css">
</style>
</head>
<body>
<div>
<?php
echo "<form action='{$_SERVER['PHP_SELF']}' method=post>n";
?>
<fieldset>
<legend>Choose page style</legend>
<p>
<?php
$styles = array("style1.css","style2.css","style3.css");
foreach($styles as $key=>$style)
{
$nbr = $key + 1;
$checked = (isset($_POST['style']) and $_POST['style'] == $style) ?
" checked" : "";
echo "<label>Style $nbr:<input type=radio name=style value='$style'$checked></label>n";
}
?>
</p>
<p><input type=submit value="Submit"></p>
</fieldset>
</form>
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</body>
</html>
[/code]
×

Success!

Help @Green-Beast 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.19,
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,
)...