when I use form.reset() in javascript. The function will reset the form to its original state. for example:
<form id="myForm">
First name: <input type="text" name="fname" value="??"><br>
Last name: <input type="text" name="lname"><br><br>
<input type="button" onclick="myFunction()" value="Reset form">
</form>
<script>
function myFunction() {
var form = document.getElementById("myForm");
form.reset();
}
</script>
when I running this code the first input field will be reset to "??" (which is the original value). How does javascript get this value? Can I access it?
I am building an website which need to check if user has changed any value of the form. If nothing changes I want to stop user from submitting the form. that's why I am asking is there any way I can have a general method to check if the current value of some field is equal to its original value.
Aucun commentaire:
Enregistrer un commentaire