There are two ways to solve this error that I figured out. First thing if you want to use reset() then, use the following code:
<form id="result">
<input type="text">
<input type="button" value="Reset" onclick="clear1()"></form>
<script>
function clear1(){
document.getElementById("result").reset();}</script>
So if you see here, I have used the tag. Three errors I found in your markup were:
- clear() method is already reserved in javascript. clear() method in JavaScript is used for the removal of all the elements from a map and make it empty. So, instead use any other function name like clear1() just like I did.
- reset() function works for the tag. So instead of giving input tag an id give that id to the tag.
- You don't have to use the value in reset() method
Use this method when you have a lot of input tags to perform with. Just wrap it with a tag.
Another method is easy when you have only one or two tags.
<input type="text" id="result">
<input type="button" value="Reset" onclick="clear1()">
<script>
function clear1(){
document.getElementById("result").value= ''}
</script>
FormElement.reset()resets a form, if that's what you want... or maybe you want something likedocument.getElementById('result').value = 'some value here';