最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Getting "object expected" error when trying to call a function in javascript - Stack Overflow

programmeradmin1浏览0评论

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>

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>
Share Improve this question asked Apr 2, 2013 at 6:20 user2234760user2234760 1433 gold badges5 silver badges16 bronze badges 3
  • Try with just alert, no "window." – elclanrs Commented Apr 2, 2013 at 6:21
  • 1 @elclanrs: alert === window.alert – Michael Geary 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. – elclanrs Commented Apr 2, 2013 at 6:36
Add a ment  | 

1 Answer 1

Reset to default 1

change

<script type="text/javscript">

to

<script type="text/javascript"> //you missed "a" in script tag
发布评论

评论列表(0)

  1. 暂无评论