user1845203
user1845203

Reputation: 21

Novice HTML - Buttons don't work correctly

I'm trying to create my very first HTML code. My code is:

<html>
<head>
</head>
<body>
<input type="button" id="apply" value="Push Me" onclick="javascript:faa();" />
<input type="button" id="apply" value="No, Push Me Instead" onclick="javascript:foo();"     />
Official website of Foocorp Inc. (Not really.)
</body>
<script type="text/javascipt">
function faa(e)
{

alert('Nope, it is the other button.');
}
</script>
<script type="text/javascript">
function foo(e)
{

alert('You have destroyed your computer. Thank you for your time.');
window.close();
}
</script>
</html>

Whenever I push the button with value "No, Push Me Instead" it works fine. The button "Push Me" doesn't do anything when I push it. What am I doing wrong?

Upvotes: 0

Views: 57

Answers (3)

PVR
PVR

Reputation: 1

You have to change script type spelling, as there is a spelling mistake

<script type="text/javascript">

Upvotes: 0

Julien Altieri
Julien Altieri

Reputation: 778

Works fine when I move the other function to the same script:

<script type="text/javascript">
    function foo(e)
    {

        alert('You have destroyed your computer. Thank you for your time.');
        window.close();
    }

        function faa(e)
    {

        alert('Nope, it is the other button.');
    }
</script>

Upvotes: 0

Quentin
Quentin

Reputation: 943649

text/javascipt should have an r in it.

HTML 5 makes the type attribute for script elements optional when you are writing JavaScript. When you are dealing with JS, the attribute serves no purpose other then to be an opportunity to make types that break your code so omit it entirely.

Upvotes: 4

Related Questions