show hidden div section based on if statement
12,603
you cannot call javascript function from PHP, PHP is server side based and stands for Preprocesing Hypertext while Javascript is browser based.
You could use:
<?php
if ($_GET['id'] == 'scheduler') {
$showdiv = 'scheduler';
}
else if ($_GET['id'] == 'test') {
$showdiv = 'test';
}
else if ($_GET['id'] == 'super') {
$showdiv = 'super';
}
echo "<script type=\"text/javascript\">document.getElementById('".$showdiv."').style.display = 'block';</script>";
?>
but that should be at bottom of the page, after those divs are loaded.
Author by
php_javascript_html_dev
Updated on June 04, 2022Comments
-
php_javascript_html_dev almost 2 years
I have a few hidden divs on page like this
<div class="form" id="scheduler" style="display: none;"> <div class="form" id="test" style="display: none;"> <div class="form" id="super" style="display: none;">
I would like a jscript which can be called to show these hidden divs based on criteria like this
<?php if ($_GET['id'] == 'scheduler') { call jscript function (show div id:scheduler in this case) } else if ($_GET['id'] == 'test') { call jscript function (show div id:test in this case) } else if ($_GET['id'] == 'super') { call jscript function (show div id:super in this case) } ?>
thanks.
-
php_javascript_html_dev over 12 yearsahh! Mihai > you just killed it just what i wanted after lot of head banging.. thanks much