IlPrincipe
IlPrincipe

Reputation: 13

Javascript Fails to Execute

For even a simple block of inline JavaScript in an HTML page, such as:

<script type="text/javascript">
var Hi= "Hi"; 
function SayHi () 
{
alert(Hi);  
}
</script>

any browser that I test this code in (Chrome, IE, Mozilla etc) fails to execute this code. I can only assume that something must have been disabled for Javascript not to run, however I am completely clueless as to the cause of this problem.

Any suggestions would be greatly appreciated.

Upvotes: 1

Views: 354

Answers (2)

user918953
user918953

Reputation: 173

you are not calling the function. add a call to that function before script closing tag

    SayHi();
</script

Upvotes: 0

cillierscharl
cillierscharl

Reputation: 7117

You've defined the function and the variable to alert but you have not called the function.

<script type="text/javascript">
    var message = "Hi"; 
    function sayHi() 
    {
        alert(message);  
    }
    sayHi();  // Call the function.
</script>

Upvotes: 2

Related Questions