0

I have a form which encompasses a text box and a drop down menu.

I am having a spot of bother administering a clear all function which will reset all of the input values on each separate element back to default.

Any steering would be appreciated.

<h1>Weekly Pay Calculator</h1>




    <script>

        function myFunction() {

        var user = document.getElementById("user").value;
        var hours = document.getElementById("hours").value;
        var total = hours * 10;
        document.getElementById("result").innerHTML = user + " " + "£" + total + " " + "is your total pay for the shifts.";
        };


        function clearForm()
        {
            $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');
            $(':checkbox, :radio').prop('checked', false);
        };


    </script>













    User ID <input type="text" id="user" maxlength="4" size="4"><br>


    <h3>Weekly Hours at (£10 per hour)</h3>

    <select id ="hours">
      <option value="">0</option>
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <option value="5">5</option>
    </select>


    <br>


    <p>&nbsp;</p>


    <br>


    <p>&nbsp;</p>

    <input type="submit" value="Net Pay" onclick="myFunction()">
    <input type="submit" value="Clear Screen" onclick="clearForm()">

    <p>&nbsp;</p>

    <h4 id="result"></h4>
Syntax Killer
  • 113
  • 2
  • 10
  • 1
    if it's an actual HTML `form` element, `reset` function is the way to go. – Mouser Mar 26 '17 at 21:02
  • 1
    Possible duplicate of [How to reset (clear) form through JavaScript?](http://stackoverflow.com/questions/3786694/how-to-reset-clear-form-through-javascript) – Mouser Mar 26 '17 at 21:04
  • Possible duplicate of [Clear form fields with jQuery](http://stackoverflow.com/questions/6364289/clear-form-fields-with-jquery) – Paolo Mar 26 '17 at 21:04
  • Put them in a `
    ` and call [`reset()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reset) (or just use a `
    – Bergi Mar 26 '17 at 21:36
  • I have tried to wrap them in a form and about 109 different divs and call it. I can't get it to work – Syntax Killer Mar 26 '17 at 21:37

0 Answers0