Html:
<!DOCTYPE html>
<html>
<head>
<SCRIPT language="JavaScript" src="mapbody.js"></SCRIPT>
</head>
<body>
<A HREF="javascript:a_message()">Click for a message..</A>
</body>
</html>
mapbody.js:
function a_message()
{
alert('I came from an external script! Ha, Ha, Ha!!!!');
}
When I pull up the web page and click the link nothing happens. Both files are in the same folder. What am I missing?
Several things:
language-attribute in thescript-tag is obsolete. Usetype="text/javascript"instead.onclick-attribute, not thehref.A proper implementation might look like this:
Also, binding function-calls to an HTML-Element using the
onclick(or any otheronXX-attribute) is old-school. Library’s like jQuery enable you to use CSS-selectors to bind actions on certain HTML-elements, which allows a full separation of HTML and JavaScript.