开发者

javascript function is not a function

This is the javascript code im using.

<script language="javascript" type="text/javascript">
function cancelevent()
    {
        input_box=confirm("Are you sure you want to cancel?");
        if (input_box==true) {
            document.cancelevent.submit();
        } else {
        }

    }
</script>

This is the form thats being submitted:

<form name=cancelevent method="post" action="whor.php">
<input type="hidden" name="owner" value="owner">开发者_开发问答;
<a href="javascript:cancelevent()">Cancel</a>
</form>

I have this form on 2 different pages. One page it works, the other, i get this error

Error: document.cancelevent.submit is not a function

Ive literally copy and pasted the code from the working page to the 2nd page....no idea what is going on or why it would do this.


I think the problem is that the HTML form and the javascript function have the same name!


Put an id on your form

<form id="cancelEventForm" name=cancelevent method="post" action="whor.php">

And use

document.getElementById('cancelEventForm').submit();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜