Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't my button function clear() working?

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.

like image 678
Ceelos Avatar asked Aug 12 '26 07:08

Ceelos


1 Answers

Try changing the name of your function.

Is "clear" a reserved word in Javascript?

like image 173
Nick Rolando Avatar answered Aug 15 '26 00:08

Nick Rolando



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!