0
<?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();
}
Alexis Leclerc
  • 1,303
  • 1
  • 16
  • 26
WackyMole
  • 49
  • 1
  • 7
  • 1
    Have you tried `$("#mydivm").delay(5000).fadeOut().empty();`? – Alexander Scholz Aug 06 '13 at 20:00
  • 8
    Please look in the [JavaScript error console](http://www.netmagazine.com/tutorials/javascript-debugging-beginners). I bet there's an error message about `getElementById` not being a function. – JJJ Aug 06 '13 at 20:01
  • 1
    To complete Juhana's statement: `document.getElementById()` – Jeff Noel Aug 06 '13 at 20:02
  • check out: http://stackoverflow.com/questions/820951/hide-div-after-a-few-seconds – kery Aug 06 '13 at 20:05
  • $("#mydivm").delay(5000).fadeOut().empty(); This worked for some reason. and Juhana before I did have the error. Thanks guys – WackyMole Aug 06 '13 at 20:06
  • check out: http://stackoverflow.com/questions/820951/hide-div-after-a-few-seconds – kery Aug 06 '13 at 20:06

2 Answers2

3

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';
Fotiman
  • 111
  • 7
0

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 = '';
federico-t
  • 12,014
  • 19
  • 67
  • 111