Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onClick JavaScript function inside HTML-form

I cant't get a simple button to work when it is inside a html form, while it works normally when not inside a html form.

This code doesn't work:

<head>
    <script langauge="JavaScript">
    function reset(){
        alert('test')
    }
    </script>
</head>

<body>
<form name="nyform">
    <input type="button" value="Reset" onClick="reset()">
</form>
</body>

While this one does:

<head>
    <script langauge="JavaScript">
    function reset(){
        alert('test')
    }
    </script>
</head>

<body>
    <input type="button" value="Reset" onClick="reset()">
</body>

What is the reason for this, and how can I correct it?

Thanks

like image 860
user1626227 Avatar asked Nov 12 '12 16:11

user1626227


1 Answers

This happens because the function reset() has a different meaning inside a form, and your custom function doesn't override it. I changed the function name to reset2 and it all worked as expected.

like image 58
Patrickdev Avatar answered Sep 25 '22 01:09

Patrickdev