1function onChange() {
2 const password = document.querySelector('input[name=password]');
3 const confirm = document.querySelector('input[name=confirm]');
4 if (confirm.value === password.value) {
5 confirm.setCustomValidity('');
6 } else {
7 confirm.setCustomValidity('Passwords do not match');
8 }
9}
1var check = function() {
2 if (document.getElementById('password').value ==
3 document.getElementById('confirm_password').value) {
4 document.getElementById('message').style.color = 'green';
5 document.getElementById('message').innerHTML = 'matching';
6 } else {
7 document.getElementById('message').style.color = 'red';
8 document.getElementById('message').innerHTML = 'not matching';
9 }
10}
1<form>
2 <label>Password: <input name="password" type="password" onChange="onChange()" /> </label><br />
3 <label>Confirm : <input name="confirm" type="password" onChange="onChange()" /> </label><br />
4 <input type="submit" />
5</form>