Click event on button doesn't seem to fire

I'm not new to HTML or JavaScript, though I don't use them often. I am, however, very new to PHP, and am currently facing a weird issue when trying to get a click event on a button in my HTML which is imbedded in PHP:

<?php
session_start();
if(!(IsSet($_SESSION["username"])) && $_SESSION["username"] == "") {
?>
<!DOCTYPE html>
<html lang="de">
<head>
<title>Blah</title>
<meta charset="utf-8">
</head>
<body>
<button type="button" onclick="function() { alert('Moo!'); }">Some button</button>
</body>
</html>
<?php
} else {
}
?>

Nothing happens when I click on the button. Yes, there's of course more markup in the original, but it's not relevant to my question. The W3C markup validation service says there are no errors, and when I alert moo from a script at the bottom of the body tag it works fine as well. It looks like the click event doesn't fire... Any idea why?

#javascript #php #html

2 Likes1.75 GEEK