2

The window.alert function does not work and the debugger in internet explorer highlights

registerForm()

in the onclick event on line 15 and gives the error "Object Expected".

<!DOCTYPE html>
<head>
<title></title>
<meta charset="utf-8" />
<script type="text/javscript">
/* <![CDATA[ */
function registerForm() {
window.alert("Function is working");
}
/* ]]> */
</script>
</head>
<body>
<form action="" method="get" enctype="application/x-www-form-urlencoded">
<p><input type="button" value="Register" onclick="registerForm();" /></p>
</form>
</body>
</html>
</body>
3
  • Try with just alert, no "window." Commented Apr 2, 2013 at 6:21
  • 1
    @elclanrs: alert === window.alert Commented Apr 2, 2013 at 6:23
  • I know, but you're never wrong to assume it could be an IE bug xD. Who knows, maybe it changes the context of window for some unknown reason. Seems like this is not the case by looking at the answer. Commented Apr 2, 2013 at 6:36

1 Answer 1

1

change

<script type="text/javscript">

to

<script type="text/javascript"> //you missed "a" in script tag
Sign up to request clarification or add additional context in comments.

4 Comments

Better yet, get rid of type="text/javascript" entirely. Also get rid of the CDATA stuff. Don't need any of that.
Thanks Sudhir. I know it's not technically necessary to include the CDATA stuff and such but I always include it anyways so that it will pass through the w3c validator.
No, you don't need CDATA or type="text/javascript" to pass the validator. Try it and see. I took both of those out of your page and the only two validation errors were the extra </body> at the end, and the empty action="" attribute. Fix those and you're golden.
Isn't specifying "text/javascript" more efficient for the browser though?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.