Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
88
rated 0 times [  95] [ 7]  / answers: 1 / hits: 17839  / 10 Years ago, sun, february 16, 2014, 12:00:00

I have a registration page and I want to compare two passwords (input fields) to be equal before writing it to a websql database.
I cannot seem to get it to work.
Any ideas?



function addTodo() {
var todo = document.getElementById(todo);
var todo2 = document.getElementById(todo2);

if(todo != todo2) {
alert(Yours passwords do not match);
} else {
curatio.webdb.addTodo(todo.value);
todo.value = ;
alert(Your Registration was successfull);
setTimeout(function () {
window.location.href = login.html;
}, 1000);
}
}


<div data-role=fieldcontain >
<label for=todo>
&nbsp;Password
</label>
<input name= id=todo placeholder= value= type=password required>
</div>


<div data-role=fieldcontain >
<label for=todo2>
&nbsp;Retype your Password
</label>
<input name= id=todo2 placeholder= value= type=password required>
</div>

More From » javascript

 Answers
155

You're comparing the elements instead of their values.



var todo = document.getElementById(todo);
var todo2 = document.getElementById(todo2);

if(todo != todo2) { // Oops


todo and todo2 are 2 different <input> elements.



Try using .value:



if(todo.value !== todo2.value) {

[#72495] Friday, February 14, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tylerdamiena

Total Points: 139
Total Questions: 90
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
tylerdamiena questions
;