-1

I have done this before but now I'm using the same technique on a new website I'm making but it doesn't work anymore. I went to the other website I've done before and the javascript button still works there. So it could be that I am doing something wrong with this code, but everything looks perfect! When I click the button Submit Globe which should call the function SubmitGlobe() and pops out a message box but it doesn't. This structure again works on my other website.

<html>
<head>
<link rel="icon" type="image/png" href="/Favicon.png">
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Test</title>
</head>
<body style="color: rgb(0, 0, 0); background-color: rgb(251, 255, 221);" alink="#000099" link="#000099" vlink="#990099">

<div align="Center">

</div>
<br>

<input onclick="SubmitGlobe()" type="button" value="Submit Globe">

<script type="text/javascript">
Function SubmitGlobe()
{
alert("I am an alert box!")
}
</script>    
</body>
</html>
Jay
  • 590
  • 6
  • 13
  • 29
  • 3
    its `function` not `Function`. – Yogesh Suthar Jun 22 '13 at 09:04
  • @YogeshSuthar: Already answers are given by fellow users, what makes your comment ? – Mahesh.D Jun 22 '13 at 09:09
  • @Jay: For `javascript` naming conventions go through with [this link](http://stackoverflow.com/questions/921133/javascript-naming-conventions) – Mahesh.D Jun 22 '13 at 09:12
  • @Mahesh.D - because for such a simple error (typo) it's probably best just to post a comment. An answer to a question like this isn't going to help others in the future. – Joe Jun 22 '13 at 10:17
  • @Joe: I'm agree with you but "Nisarg Patel" and other already given answer before "Yogesh Suthar" then what is the need of comment here ? – Mahesh.D Jun 22 '13 at 10:20

5 Answers5

1

put f in lowercase

    function SubmitGlobe(){
}
Nisarg
  • 3,024
  • 5
  • 32
  • 54
0

My idea is to put <script> into head. Some browsers require functions to be defined already before execution. Also, do not use CamelCase for declaring functionw. It is only suitable for defining objects (Classes)

<html>
<head>
<script type="text/javascript">
function submitGlobe()
{
alert("I am an alert box!");
}
</script>  
<link rel="icon" type="image/png" href="/Favicon.png">
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Test</title>
</head>
<body style="color: rgb(0, 0, 0); background-color: rgb(251, 255, 221);" alink="#000099" link="#000099" vlink="#990099">

<div align="Center">

</div>
<br>

<input onclick="submitGlobe();" type="button" value="Submit Globe">


</body>
</html>
sybear
  • 7,837
  • 1
  • 22
  • 38
0

It should be like

<input onclick="SubmitGlobe();" type="button" value="Submit Globe">

You have missed ; after function and your function should be like

function SubmitGlobe() {
    //Do the stuff
}
GautamD31
  • 28,552
  • 10
  • 64
  • 85
0

I suspect you get:

Uncaught SyntaxError: Unexpected identifier Uncaught ReferenceError: SubmitGlobe is not defined

Because you're using Function instead of function.

Replace Function with function.

Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
0

use this it will work fine. just copy and paste this code where you have written this

<html>
<head>
<script type="text/javascript">
function submitGlobe()
{
alert("I am an alert box!");
}
</script>  
<link rel="icon" type="image/png" href="/Favicon.png">
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Test</title>
</head>
<body style="color: rgb(0, 0, 0); background-color: rgb(251, 255, 221);" alink="#000099" link="#000099" vlink="#990099">

<div align="Center">

</div>
<br>

<input onclick="return submitGlobe()" type="button" value="Submit Globe">


</body>
</html>

here in onclick i have used "return submitGlobe()" which will return the same nane i.e. submitGlobe () written inside your script tag also your alert() should end with a semicolon.

Php developer
  • 446
  • 4
  • 18