Ad

Best Practices For Submitting The Form On Every Input Change

I have a form with lots of inputs (checkboxes / textboxes / selects and so on). These are search filters. I would like to submit the form on every input change.

I was thinking that I should put for every input $("...").on(change, function(){ form.submit();}), but I feel this might not be the best approach.

So, what is the best practice?

Ad

Answer

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(function(){
  $( ".target" ).on('change',function(e) {
    console.log(e.target.value)
  });
});
</script>
</head>
<body>
<form>
  <input class="target" type="text">
  <select class="target">
    <option value="option1" selected="selected">Option 1</option>
    <option value="option2">Option 2</option>
  </select>
</form>
</body>
</html>

Ad
source: stackoverflow.com
Ad