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();
}
6
  • 1
    Have you tried $("#mydivm").delay(5000).fadeOut().empty();? Commented Aug 6, 2013 at 20:00
  • 8
    Please look in the JavaScript error console. I bet there's an error message about getElementById not being a function. Commented Aug 6, 2013 at 20:01
  • 1
    To complete Juhana's statement: document.getElementById() Commented Aug 6, 2013 at 20:02
  • check out: stackoverflow.com/questions/820951/hide-div-after-a-few-seconds Commented Aug 6, 2013 at 20:05
  • $("#mydivm").delay(5000).fadeOut().empty(); This worked for some reason. and Juhana before I did have the error. Thanks guys Commented Aug 6, 2013 at 20:06

2 Answers 2

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';
Sign up to request clarification or add additional context in comments.

Comments

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 = '';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.