...

View Full Version : show div when php variable $_GET is set and ....



elem
09-25-2011, 03:39 AM
i'm trying to change hidden div's display to block if the certain conditions in php will be true. so what i have is:



<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<?php if((isset($_GET['section'])) AND ($_GET['section']=="booking") AND (isset($_GET['action'])) AND ($_GET['action']=="edit")) {

$query = mysql_query("SELECT * FROM booking WHERE id='$id'");
while ($row = mysql_fetch_object($query)) {

$id=$row->id;

if($id=="1") {

echo("<script type=\"text/javascript\">

document.getElementById('mydiv').style.display = 'block';

</script>");

}

}

}

?>
</head>


but it doesn't work ..... when you view page's source in the browser, this is what comes up before the end of head section:

<script type="text/javascript">

document.getElementById('flavours').style.display = 'block';

</script>

so php seems to work, but js doesn't for some reason, i still can't see the #mydiv. what am i doing wrong guys ?

DaveyErwin
09-25-2011, 02:13 PM
i'm trying to change hidden div's display to block if the certain conditions in php will be true. so what i have is:

but it doesn't work ..... when you view page's source in the browser, this is what comes up before the end of head section:

<script type="text/javascript">

document.getElementById('flavours').style.display = 'block';

</script>

so php seems to work, but js doesn't for some reason, i still can't see the #mydiv. what am i doing wrong guys ?

you can only use document.getElementById after
the document is ready, you should put that in
aa onload handler , or at the bottom of page
just before </body>

sunfighter
09-25-2011, 04:01 PM
An example to show you what DaveyErwin said.


<?php
$id = "1"; // change 1 to something else and div does not appear
?>
<html><head></head>
<body>
<div id="mydiv" style="display:none;"> Just a bunch of Monkeys</div>

<script type="text/javascript">
var test = <?php echo $id; ?>;
if (test == '1')
document.getElementById('mydiv').style.display = 'block';
</script>
</body></html>

elem
09-25-2011, 05:26 PM
Thanks a lot gents, indeed script was just in a wrong spot.

Thanks again :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum