Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
176
rated 0 times [  183] [ 7]  / answers: 1 / hits: 17388  / 9 Years ago, wed, december 30, 2015, 12:00:00

I want to reset all the values of my inputs that I have within a form (textboxs, selects, checkboxs, radiobuttons,...) like if I reload the web, but when I touch a button.



$(#button).click(function () {
//Here the code that I need
});

More From » jquery

 Answers
8

You can reset a form using JavaScript built-in reset() function:



$(#otra).click(function () {
$(#yourFormId)[0].reset();
});


Working demo:





$(#otra).click(function () {
$(#yourFormId)[0].reset();
return false; // prevent submitting
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>

<form id=yourFormId>
<input type=checkbox name=myCB/>
<input type=text name=myTB value=/>

<button id=otra>Reset</button>
</form>




[#63895] Monday, December 28, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
terrence

Total Points: 120
Total Questions: 115
Total Answers: 87

Location: England
Member since Fri, May 22, 2020
4 Years ago
;