BRSKZR
BRSKZR

Reputation: 33

How to clear textbox in html

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

Answers (5)

AsTeR
AsTeR

Reputation: 7541

If you are using JQuery:

$("#v1").val('');

Upvotes: 0

dknaack
dknaack

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

Liam Martens
Liam Martens

Reputation: 741

If all of your inputs are wrapped in a form you could also call .reset() on that form

Upvotes: 1

doniyor
doniyor

Reputation: 37914

$('#clear').click(function(){
 $('#v1, #v2, #v3, #v4').val('');   
});

Upvotes: 1

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Try this :

$('#clear').click(function(){
    $("#v1,#v2,#v3,#v4").val("");
});

Upvotes: 1

Related Questions