Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
Reset (reset to previous value) only the form fields that are changed

I need to reset only the form fields that are changed (reset to previous value).

I tried to use the reset but it completely resets the entire form and I don't need this.

How can I do this?

function clearResult() {
            document.getElementById("save").reset();
        }
<div class = "container">
         <form method="post" id="save" onload="onLoad()">
             <div class="field">
                 <label for="id"> ID:</label>
                 <input type="number" id="id" name="id" />
             </div>
             <div class="field">
                 <label for="type"> Fragment Type: </label>
                 <input type="text" id="type" name="type" />
             </div>
             <div class="button">
                 <button type="submit" class="full">Save changes</button>
                 <input type="button" value="Cancel" onclick="clearResult()" />
             </div>
         </form>
     </div>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

First of all you should to store the predefined values of form elements to set them back when you want to reset them back.

Then you can use this globally defined initial values to set them back whnever reset event occurs.

var id, type;
const form = document.getElementById('save');

document.onload = (event) => {
  id = form.id.value;
  type = form.type.value;
};

function clearResult() {
  form.id.value = id;
  form.type.value = type;
};
about 4 years ago · Juan Pablo Isaza Report

0

It was simple. When page load just get values from that fields. Make with document.onload:

var firstValue = document.getElementById("yourFieldId").value;

After form submit get values like below:

var currentValue = document.getElementById("yourFieldId").value;

And after submit in reset check if CURRENT VALUES equal with VALUES FROM FIRST TIME Example

if(firstValue != currentValue){
  document.getElementById("yourFieldId").value = firstValue;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!