5

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

2
  • 4
    Maybe change your function's name.. I am thinking that reset may be a reserved word. Commented Nov 12, 2012 at 16:17
  • He is right, reset() is a JavaScript-function which clears/empties form fields. The second sample just works because no form-tag is wrapped. Commented Nov 12, 2012 at 16:22

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! It works now, I will give you credit when the time limit has passed :)

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.