Validation if any form input was changed

0

I need to check if the form has changed, ie if some input data has changed, etc. So that when you do submit , or leave the page, make some button click, or the menu is informed to the user that the data has been changed, and that have not yet been saved. I found this link , but I do not know if it is possible, I wanted it in any click that was not the submit of the page and had made the change the user was notified, to do this I have to call function in several places, or is there a function that makes this general in the form page?

    
asked by anonymous 24.09.2018 / 16:47

1 answer

2

 $('form').on('change paste', 'input, select, textarea', function(){
    $mudou=true;
});


$( "#mybutton" ).click(function() {

if ($mudou==true){

   var msj='Algo mudou no formulário, deseja envia-lo?';
   if (!confirm(msj)) { 
      return false;
   } else {
     $( "#form_name" ).submit();
   }
}  
  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formname="form_name" id="form_name">
  <input type="text" name="a" id="a" value="a" />
  <input type="text" name="b" id="b" value="b" />
  <input type="text" name="c" id="c" value="c" />
  <input type="text" name="d" id="d" value="d" />
  <input type="text" name="e" id="f" value="e" />
  <input type="text" name="f" id="e" value="" />
  <select name="two_g">
    <option value="111">111</option>
    <option value="222">222</option>
    <option value="333">333</option>
  </select>
</form>
<button id="mybutton">submit</button>
    
24.09.2018 / 20:10