views:

205

answers:

6

How do I pop up an alert in Javascript?

I tried alert"HELLO" but that didn't work.

Can someone tell me the correct syntax?

+3  A: 

You need to add parentheses:

alert("HELLO");
Kevin
+2  A: 

alert("Hello");

ApoY2k
+3  A: 
<script type="text/javascript" >
  alert("hello");
</script>
Shadi Almosri
A: 
<script type="text/javascript">alert("Hello");</script>
despart
+2  A: 

if you're having problems with alerts, it probably means your javascript is disabled in your browser, but if it isn't these methods should solve your issue.

<script type="text/javascript" >
    window.alert("Hello World!");

    alert("Hello World!");
</script>
Graham
+2  A: 

Unlike VBScript, Javascript requires parentheses around function calls.

Therefore, you need to write alert("Hello!");

It's also prefereable (but not required) to end every statement with a semicolon ;.

Finally, if you aren't already, you need to put it in a script block, like this:

<script type="text/javascript">
    alert("Hello!");
</script>

In responce to the end of your original question, there is no "javascript exe". You can put javascript inside a script tag in an HTML page, or you can make a standalone .js file and double-click on it (in Windows) to run it using WSH.

SLaks