Im trying to do a link from one page to another, on the link itself I send a variable that the receiving page gets with php, then I need the php to echo out js to change the css display on two divs, changing the div whose default css is block to that of hidden and a second div whose default css is none to that of block. I have suucesfully passed the variable within the url, and the js to change the second div to block works, however the 1st div css doesnt seem to change to none as the div still shows
PHP code
if (isset($_GET['display'])) {
if(!isset($_GET['yes'])) {
echo '<style type="text/css">
#slideshow {
display: none;
}
</style>';
echo '<style type="text/css">
#aboutus {
display: block;
}
</style>';
}
}else{
};
Can anyone help me resolve this please
2 Answers 2
Are you sure you don't mean this:
if($_GET['display'] == 'yes') {
I would pass an integer value rather than 'yes' and 'no'.
Then do it this way:
<?php
ob_start("ob_gzhandler");
header('Content-Type: text/html; charset=utf-8');
header('Connection: Keep-Alive');
header('Keep-Alive: timeout=5, max=100');
header('Cache-Control: max-age=84600');
header('Vary: Accept-Encoding');
echo <<<EOT
<!DOCTYPE html>
<html lang="en"><head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>page Title</title>
<style type="text/css">
.hide{display:none;}
</style>
</head><body><div id="page">
EOT;
ob_flush();
$display = inval($_GET['display']);
$aboutclass = array(' class="hide" ','');
$slideclass = array('',' class="hide" ');
echo '<div id="aboutus" ' . $aboutclass [$display] . '>'
echo '<div id="slideshow" ' . $slideclass [$display] . '>'
echo '</div></body></html>';
ob_end_flush();
1 Comment
I found a solution, using the following code
PHP
if(isset($_GET['display']) != 'yes'){
$slider = 'block';
$aboutus = 'none';
}else{
$slider = 'none';
$aboutus = 'block';
}
Then I removed the display stying from the external stylesheet for the .slideShow and .aboutus and added inline styles just for the display within the head section of the html code as follows
<style type="text/css">
.sliderWrapper {
display: <?php echo $slider; ?>
}
.aboutUs {
display: <?php echo $aboutus; ?>
};
</style>
Then it worked as required.
?display=yes, then instead ofif(!isset($_GET['yes']))useif(trim($_GET['display']) != 'yes')