user5863968
user5863968

Reputation:

HTML/Javascript button doesn't return alert

I made a HTML page with a button, that displays a message saying: "This is a message". Everything looks fine, but when I press the button don't get a message. I checked for any mistakes, but I couldn't find anything. What am I doing wrong?

<!DOCTYPE html>

<html>
<head>
    <title>Testing JavaScript</title>
    <link rel="stylesheet" type="css" href="Button.css">
</head>

<body>
    <h1>Javascript</h1>
        <p>I am testing JS on this page.<br/>
        This is a button.</p>

    <script>
        var message = "This is a message";
        function popUp()
        {
            alert(message);
        }
    </script>
    <button type="button" onclick="press()">Press me!</button>
</body>
</html>

Upvotes: 0

Views: 186

Answers (3)

Sirlero
Sirlero

Reputation: 71

You should call to onclick="popUp()"

Upvotes: 3

404
404

Reputation: 1155

You dont have a function named as "press()" declared, change the code

<!DOCTYPE html>

<html>
<head>
    <title>Testing JavaScript</title>
    <link rel="stylesheet" type="css" href="Button.css">
</head>

<body>
    <h1>Javascript</h1>
        <p>I am testing JS on this page.<br/>
        This is a button.</p>

    <script>
        var message = "This is a message";
        function popUp()
        {
            alert(message);
        }
    </script>
    <button type="button" onclick="popUp()">Press me!</button>
</body>
</html>

Upvotes: 1

Szabolcs D&#233;zsi
Szabolcs D&#233;zsi

Reputation: 8843

Instead of onclick="press()":

onclick="popUp()"

Upvotes: 2

Related Questions