Reputation: 49
<?php
if( isset($_GET['message']) ) {
$message = urldecode($_GET['message']);
echo "<h2 id='mydivm'>". $message . "</h2>";
?>
<script>
setTimeout( function() {
getElementById(mydivm).value='';
// the alert is working
alert("hello");
}, 5000);
</script>
<?php
}
?>
I am trying to hide the $message after 5 seconds through #mydivm
. However I can't get regular JavaScript to work or jQuery. Alert works when it is alone. I also have tinymic, but I don't think that is interfering. I have tried putting it outside the PHP
setTimeout(fade_out, 5000);
function fade_out() {
$("#mydivm").fadeOut().empty();
}
Upvotes: 0
Views: 168
Reputation: 111
getElementById is a method of the document. Also, you're not passing it a string. You need to change your code from this:
getElementById(mydivm).value='';
to this:
document.getElementById('mydivm').value='';
EDIT: Looking closer, setting the value attribute is not the correct way to do that either. You would need:
document.getElementById('mydivm').innerHTML='';
or better yet:
document.getElementById('mydivm').style.display='none';
Upvotes: 3
Reputation: 12341
Maybe this is not where the error is coming from, but getElementById
is a function that belongs to the document
object. Most likely, what's happening is that you're receiving a "undefined function getElementById" which you are not seeing. Use it this way:
document.getElementById('mydivm').value = '';
Upvotes: 0