3

Any particular reason why my button isn't working when I click on it? Here's the code.

    <script>
    function save() {
        if (isNaN(document.form.result.value) || document.form.result.value == 0) {
        document.getElementById('hours').innerHTML = "There was an input error, make sure that: <br> The calculator field is not empty <br> Only include numbers as an input";
        document.getElementById('hoursdiv').style.background = "yellow";
        } else {
        savedvalue = document.form.result.value;
        document.getElementById('hours').innerHTML = "Hours Worked This Week: " + savedvalue;
        document.getElementById('hoursdiv').style.background = "";
            }
    }
    function clear() {
        alert("hi");
    }
   </script>

    <div>
    <!-- Save Button -->
<input class = "customSubmitButton" type="button" onClick="save();" value="Save">

   <!-- Clear Button -->
<input class = "customSubmitButton" type="button" onClick = "clear()" value = "Clear">

    <div id = "hoursdiv">
        <p>
           <strong id = "hours"> </strong>
        </p>
    </div>
</div>

The Save button works just fine.

Ceelos
  • 1,116
  • 2
  • 14
  • 35

1 Answers1

7

Try changing the name of your function.

Is "clear" a reserved word in Javascript?

Community
  • 1
  • 1
Nick Rolando
  • 25,879
  • 13
  • 79
  • 119
  • 1
    "clear is not a reserved keyword": http://stackoverflow.com/questions/7165570/is-clear-a-reserved-word-in-javascript – showdev Jul 19 '13 at 22:37
  • 2
    Javascript console says: `document.clear() is deprecated. This method doesn't do anything.` – Barmar Jul 19 '13 at 22:39