-1

I have a question. I am trying to clear the text fields of a form once a button is clicked. This is the HTML for the input type:

<input type="button" id="clear_entries" value="Clear Entries">

This is my Jquery code:

$("#clear_entries").click(
                    function() {                        
                        $(":text").val("");                                 
            })
        

nothing happens when I click the Clear Entries button and I am not sure why. I have confirmed with an alert statement(which I have removed from the above snippet) within the function to confirm that the function is being invoked.

javaperson
  • 109
  • 1
  • 12

3 Answers3

1
$("#clear_entries").click(function(){                        
     $('input[type="text"]').val(""); 
 })

check the link for fiddle code

enter link description here

0

$('#clear_entries').on('click', function () {
  $(".form input[type=text]").val("");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="form">
<label for="">Name : </label> <input type="text">
<label for="">email : </label> <input type="text">
<input type="button" id="clear_entries" value="Clear Entries">
</form>
SahanSira
  • 34
  • 6
0

Thanks for the response everyone. I just realized that I made the mistake of placing this within the function meant for another button. Also just to confirm, both

$(":text").val(""); 

and

$('input[type="text"]').val("");

give the desired result. Thank you once again.

javaperson
  • 109
  • 1
  • 12