Reputation: 33
I just want to clear textbox my html form. I made it and clear but i write something in again , it seen by my function as empty. How can do it ? I did it like this below;
$('#clear').click(function(){
document.getElementById("v1").value="";
document.getElementById("v2").value="";
document.getElementById("v3").value="";
document.getElementById("v4").value="";
});
Upvotes: 1
Views: 2413
Reputation: 60516
Use the jQuery val() method to set a value.
$('#clear').click(function(){
$('#v1, #v2, #v3, #v4').val(''):
});
If you your input elements are inside a form, you also can use the reset()
function
to reset all form elements.
<form id="myForm">
// your form elements
</form>
$('#clear').click(function(){
$('#myForm').reset():
});
Upvotes: 3
Reputation: 741
If all of your inputs are wrapped in a form you could also call .reset() on that form
Upvotes: 1
Reputation: 37914
$('#clear').click(function(){
$('#v1, #v2, #v3, #v4').val('');
});
Upvotes: 1
Reputation: 28513
Try this :
$('#clear').click(function(){
$("#v1,#v2,#v3,#v4").val("");
});
Upvotes: 1