Matt
Matt

Reputation: 179

How do I pop up an alert in JavaScript?

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?

Upvotes: 5

Views: 68428

Answers (8)

Shadi Almosri
Shadi Almosri

Reputation: 11989

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

Upvotes: 5

SLaks
SLaks

Reputation: 887479

Unlike VBScript, JavaScript requires parentheses around function calls.

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

It's also preferable (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>

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.

Upvotes: 12

user9013730
user9013730

Reputation:

There are a few ways.

  1. Use your web browser, type this code in address bar.

    javascript:alert("Hello World!")

  2. Open web developer in your web browser, go to console and type:

    alert("Hello World!")

  3. Type the code in .html or .js code as shown in other answers above.

Upvotes: -1

F.P
F.P

Reputation: 17831

Just add parantheses

alert("Hello");

Upvotes: 2

napendra
napendra

Reputation: 378

<html>
<head>
<script type="text/javascript">
  function myFunction(){
    alert("hello");
  }
</script>
 </head>
<body>
<input type="submit" onClick="myFunction()">
</body>
</html>

Here is the JavaScript function which has an alert box. This function is called by clicking on the submit button.

Upvotes: -2

Gram
Gram

Reputation: 404

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>

Upvotes: 3

David Espart
David Espart

Reputation: 11780

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

Upvotes: 0

kemiller2002
kemiller2002

Reputation: 115498

You need to add parentheses:

alert("HELLO");

Upvotes: 12

Related Questions