Reset form invalid values |
Reset form invalid values |
RainLover |
Apr 10 2019, 02:57 AM
Post
#1
|
Advanced Member Group: Members Posts: 216 Joined: 16-November 09 Member No.: 10,346 |
Here’s a sample form:
CODE <form> <input type="number"> <input type="number"> <button type="button">Reset</button> </form> var form = document.querySelector('form'); function detectChange() { var inputs = form.querySelectorAll('input'); for (var input of inputs) { if (input.value) { return true; } } } form.querySelector('button').addEventListener('click', function() { if (detectChange() && confirm('Are you sure you want to reset?')) { form.reset(); } }); DEMO I’d like the reset button to work even if the user enters non-numeric values. |
CharlesEF |
Apr 10 2019, 05:56 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Actually, isn't the form that has the reset method? An input or button can have a type of reset but doesn't that just call the reset method of the form itself?
|
pandy |
Apr 10 2019, 08:52 PM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,716 Joined: 9-August 06 Member No.: 6 |
Yes. There is no such attribute. Unless HTML 5 has come up with one.
|
Christian J |
Apr 11 2019, 04:58 AM
Post
#4
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
Yes. There is no such attribute. Unless HTML 5 has come up with one. Is nobody reading the spec anymore? https://www.w3.org/TR/html401/interact/form...def-type-BUTTON https://www.w3.org/TR/html/sec-forms.html#e...def-button-type |
Lo-Fi Version | Time is now: 28th March 2024 - 06:06 PM |