I'm trying to activate an alternative style sheet by clicking on a
hyperlink.
The problem what I have is when clicking on the link, the page jumps to the
right chapter but it wouldn't activate the alternative style sheet.
The code is:
<head>
<link rel="stylesheet" type="text/css" title="basic page style"
href="style.css">
<?php
if ($style="vert1") {echo '<link rel="stylesheet" type="text/css"
title="vertical" href="vert.css">' ."\n";}
?>
</head>
<body>
<a <?php $style="vert1"; ?> href="#vert1">jgjglkgfd dkgjlkd</a>
some content
<h2><a name="vert1"></a>blah</h2>
more content
</body>
This is the experimental site:
http://www.semi-conductor.nl/test/
What am I doing wrong?
--
Edwin van der Vaart
http://www.semi-conductor.nl/ Links to Semiconductors sites
http://members.chello.nl/e.vandervaart/ Experimental site
> What am I doing wrong?
Ummm... PHP doesn't work like that. Here is a basic stylesheet switcher
for you. It assumes that you have a directory "styles" containing
"black.css", "white.css" and "red.css".
============================ example.php =============================
<!DOCTYPE whatever>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" media="screen,projection"
<?php echo ' href="styles/' . $_GET['style'] . '.css"'; ?> >
</head>
<body>
<h1>Example</h1>
<p>The style you chose was <code><?php echo $_GET['style']; ?>.css</code>.</p>
<ul>
<li><a href="example.org?style=red">Red</a></li>
<li><a href="example.org?style=white">White</a></li>
<li><a href="example.org?style=black">Black</a></li>
</ul>
</body>
</html>
======================================================================
In short, if you want a user to interact with a PHP script, it has to be
with clicking links to reload the page, tagging on parameters at the end
of the URL; or via form submits.
One improvement to the above script would be to add a default stylesheet.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me - http://www.goddamn.co.uk/tobyink/?id=132
Thanx Toby.
It's getting late. I'll try it later of the day, so good night.
Interresting, I'll experiment with it.
[snip]
> ============================ end example.php
==============================
>
> In short, if you want a user to interact with a PHP script, it has to be
> with clicking links to reload the page, tagging on parameters at the end
> of the URL; or via form submits.
>
> One improvement to the above script would be to add a default stylesheet.
Dunno, it works great.
And how should you do that? With an if then else structure? Cause I like the
script, it's easy. I've once made one with an if then else to see if the
variable was filled but this one is easier (though it hasn't got a default
style).
--
Fabian
http://givelove.be/
> Toby A Inkster wrote:
>> One improvement to the above script would be to add a default
>> stylesheet.
>
> And how should you do that? With an if then else structure?
Well, I *was* going to leave it as an exercise to the reader, but since
you asked:
============================ example.php =============================
<!DOCTYPE whatever>
<?php
$s = $_GET['style'];
if (!($s)) { $s = 'red'; }
?>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" type="text/css" media="screen,projection"
<?php echo ' href="styles/' . $s . '.css"'; ?> >
</head>
<body>
<h1>Example</h1>
<p>The style you chose was <code><?php echo $s ?>.css</code>.</p>
<ul>
<li><a href="example.org?style=red">Red</a></li>
<li><a href="example.org?style=white">White</a></li>
<li><a href="example.org?style=black">Black</a></li>
</ul>
</body>
</html>
======================================================================
--
Duende
I noticed in a style sheet (e.g. style04.css) the following string
*{color:black;background-color:#FFC066;}
Why using the * and not e.g. body {color:black;background-color:#FFC066;} ?
8-) !
The php script (above) and a normal style sheet link works perfectly.
http://www.semi-conductor.nl/test/test2.php (php scripts)
http://www.semi-conductor.nl/test/test3.php (a style sheet link + php
script & it validates :-D )
:-| | That's it !
I go to my trailer ! :-| |