Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 377
Bacha Avatar asked May 08 '26 16:05

Bacha


1 Answers

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>
like image 199
Eddie Avatar answered May 11 '26 05:05

Eddie