Consider, I've got this code in PHP
<?php
if($count==0)
{
?>
<script>
show_my_div();
</script>
<?php } ?>
the show_my_div()
is supposed to show a division tag. But It doesn't work. Please help.
Consider, I've got this code in PHP
<?php
if($count==0)
{
?>
<script>
show_my_div();
</script>
<?php } ?>
the show_my_div()
is supposed to show a division tag. But It doesn't work. Please help.
There's no standard show_my_div
function in PHP or JavaScript. You'd have to post the content of that function for anyone to help you with it.
Outputting a div is easy in PHP:
echo "<div>content</div>";
Similarly, it's easy in JavaScript to create a div element and append it to something. Here's raw JavaScript to append a div to the end of the page:
var div = document.createElement('div');
div.innerHTML = "The content of the div";
document.body.appendChild(div);
You can append elements anywhere, not just at the end. For instance, suppose I have a div with the id foo
:
<div id="foo"></div>
...and I want to add a paragraph to the end of it:
var p, div;
div = document.getElementById('foo');
if (div) { // (Just being defensive)
p = document.createElement('p');
p.innerHTML = "The text of the paragraph";
div.appendChild(p);
}
These things are made easier if you use a JavaScript library like Prototype, jQuery, Closure, or any of several others to smooth out browser differences and give you some syntactic sugar.
Assuming show_my_div exists,
have you tried to add type="text/javascript" to your script tag?