Search code examples
javascriptjqueryreset

Resetting Values using jquery


Trying to reset value of input to blank using button and jquery, but it gives

Uncaught TypeError: $(...).reset is not a function

$(document).ready(function() {
  $("#reset_btn").click(function() {
    $("#buy").reset();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<input type="number" class="form-control" id="buy" placeholder="Buy Amount" name="buy">

<button type="button" class="btn btn-secondary" id="reset_btn">RESET</button>


Solution

  • One option to remove the value of input is to use .val(""). Basically setting the value to an empty string.

    Here is an example:

    $(document).ready(function() {
      $("#reset_btn").click(function() {
        $("#buy").val("");
      });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    
    <input type="number" class="form-control" id="buy" placeholder="Buy Amount" name="buy">
    
    <button type="button" class="btn btn-secondary" id="reset_btn">RESET</button>