0

Okay i have no idea why my second button isn't working. It seems straight forward but for some reason it is not working. The "Reset" button does not appear to be calling the clear() function.

Here is the HTML. I have two buttons that interact with a database. The first one, "Update", is to filter the search results. And the second, "Reset", is to reload the page. Right now I'm just trying to get minimal functionality out of the "Reset" button.

Here is the HTML:

 <script src = "filter.js" type="text/javascript"></script>
 ...
 <input type = "button" value = "Update" onclick = "filter(...);">
 <input type = "button" value = "Reset" onclick = "clear();">

And then the javascript in filter.js:

function filter(...) {
    ...
}

function clear() {
    alert("Alert");
}
  • 2
    possible duplicate of [Is "clear" a reserved word in Javascript?](http://stackoverflow.com/questions/7165570/is-clear-a-reserved-word-in-javascript) – showdev Apr 25 '14 at 19:59

3 Answers3

1

Seems like clear is a reserved word. Try myClear for example:

<input type = "button" value = "Reset" onclick = "myClear();">
function myClear() {
    alert("Alert");
}

Working example: http://jsfiddle.net/s8nrd/

Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
0

The reason is because clear is a reserved word, just change your functions name to "Clear":

 <input type = "button" value = "Reset" onclick = "Clear();">

function Clear() {
    alert("Alert");
} 
juvian
  • 15,875
  • 2
  • 37
  • 38
0

I believe that clear() can be referenced as Document.clear() Try to name your function differently and post result.

Also do you get any error output when you click you input ?

NMC
  • 793
  • 9
  • 18