Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Walidacja haseł
renault12
post
Post #1





Grupa: Zarejestrowani
Postów: 147
Pomógł: 0
Dołączył: 9.01.2010

Ostrzeżenie: (0%)
-----


Witam,

Mam problem dotyczący js w sprawdzaniu haseł.

Otóż mam dwa inputy w htmlu ktore służą do wpisania hasła te drugie do jego sprawdzenia, tak wygląda kod html:
  1. <tr>
  2. <td>Hasło:</td>
  3. <td><input type="password" id="pass" onBlur="checkPass()" name="pass"><div id="errorResult2"></div></td>
  4. </tr>
  5. <tr>
  6. <td>Powtórz hasło:</td>
  7. <td><input type="password" name="pass_rep" id="pass_rep" onChange="validate_pass('pass','pass_rep')"><div id="errorResult3"></div></td>
  8. </tr>


A tak js:

  1. function validate_pass(p,r){
  2. if (document.getElementById(p).value!=document.getElementById(r).value) {
  3. var errorResult3 = document.getElementById("errorResult3");
  4. if(pass_rep!='') {
  5. errorResult3.innerHTML = 'Hasła się różnią';
  6. }
  7. }
  8. }


Cały czas wywala mi błąd że hasła się różnią. W czym może być problem?
Go to the top of the page
+Quote Post
ces
post
Post #2





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 21.07.2010

Ostrzeżenie: (0%)
-----


if(pass_rep!='') jak wpiszesz drugie haslo zawsze dostaniesz true powinno raczej byc if (pass!=pass_rep)
Go to the top of the page
+Quote Post
outsider
post
Post #3





Grupa: Zarejestrowani
Postów: 267
Pomógł: 36
Dołączył: 8.08.2008

Ostrzeżenie: (0%)
-----


poprawilem drugi warunek, bo pod ta zmienna nie miales nic przypisane:
Kod
function validate_pass(p,r){
   if (document.getElementById(p).value!=document.getElementById(r).value) {
   var errorResult3 = document.getElementById("errorResult3");

       if(document.getElementById(r).value != '') {
         errorResult3.innerHTML = 'Hasła się różnią';
      }
   }
}
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 07:10