2

This is function that i created for clear text fields but when enter any custom values it doesn't clear

function clear(){

    document.getElementById('bmw1').value="";
    document.getElementById('bmw2').value="";
    document.getElementById('ans').value="";


}

The fields which created in html

<input type="text" id="bmw1" placeholder="Enter 1st Number"/>
<input type="text" id="bmw2" placeholder="Enter 2nd Number"/>
<input type="text" id="ans" placeholder="Answer"/>
<button type="button" onClick="clear()">Clear Values</button>
Ven Nilson
  • 969
  • 4
  • 16
  • 42

4 Answers4

1

You need to change the js function name from clear() to something else. Because clear() is a java script built in function/method.

The Guest
  • 698
  • 11
  • 27
0

Why re-invent the wheel? You can do that with basic HTML:

<input type="reset" value="Reset" />

Just make sure that is inside your form and it will clear all the values.

Gary Storey
  • 1,779
  • 2
  • 14
  • 19
0

I believe JavaScript already has a clear() function, try renaming your method. The following works for me :

function erase(){
        document.getElementById('bmw1').value = "";
}
Ian Wise
  • 706
  • 2
  • 10
  • 31
0

Problem is with name of function which is already reserved for Document.

Please change your function name to other and it will work well.

madoxdev
  • 3,770
  • 1
  • 24
  • 39