[javascript] how to check confirm password field in form without reloading page

Using Native setCustomValidity

Compare the password/confirm-password input values on their change event and setCustomValidity accordingly:

_x000D_
_x000D_
function onChange() {_x000D_
  const password = document.querySelector('input[name=password]');_x000D_
  const confirm = document.querySelector('input[name=confirm]');_x000D_
  if (confirm.value === password.value) {_x000D_
    confirm.setCustomValidity('');_x000D_
  } else {_x000D_
    confirm.setCustomValidity('Passwords do not match');_x000D_
  }_x000D_
}
_x000D_
<form>_x000D_
  <label>Password: <input name="password" type="password" onChange="onChange()" /> </label><br />_x000D_
  <label>Confirm : <input name="confirm"  type="password" onChange="onChange()" /> </label><br />_x000D_
  <input type="submit" />_x000D_
</form>
_x000D_
_x000D_
_x000D_

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to jquery

How to make a variable accessible outside a function? Jquery assiging class to th in a table Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Getting all files in directory with ajax Bootstrap 4 multiselect dropdown Cross-Origin Read Blocking (CORB) bootstrap 4 file input doesn't show the file name Jquery AJAX: No 'Access-Control-Allow-Origin' header is present on the requested resource how to remove json object key and value.?

Examples related to ajax

Getting all files in directory with ajax Cross-Origin Read Blocking (CORB) Jquery AJAX: No 'Access-Control-Allow-Origin' header is present on the requested resource Fetch API request timeout? How do I post form data with fetch api? Ajax LARAVEL 419 POST error Laravel 5.5 ajax call 419 (unknown status) How to allow CORS in react.js? Angular 2: How to access an HTTP response body? How to post a file from a form with Axios