Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

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

    SayHi();
</script
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top