Korzystając z okazji chciałbym przywitać się z forumowiczami. Jest to mój pierwszy post na tym forum.
Ale do rzeczy:
Posiadam skrypt który na pierwszy rzut oka powinien działać. Nie mogę (razem z nauczycielem i kolegami) znaleźć w nim błędu.
Plik: rejestracja.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Zarejestruj się</title> <link href="styleRej.css" rel="stylesheet" type="text/css" /> <script src="rejestracja.js" type="text/javascript"></script> </head> <body> <div id="rejestr"> <h1>Zarejestruj się</h1> <form name="rejestracja" > <div class="row"> <span class="label">Nazwa użytkownika:</span> <span class="formw"> <input type="text" name="nazwa" /> <span id="zlaNazwa"></span> </span> </div> <div class="row"> <span class="label">Podaj hasło:</span> <span class="formw"> <input type="password" name="haslo" /> <span id="opisHasla"></span> </span> </div> <div class="row"> <span class="label">Ponownie podaj hasło:</span> <span class="formw"> <input type="password" name="haslo2" /> <span id="zgodneHasla"></span> </span> </div> <div class="spacer" /> <center> <input type="submit" value="Wyślij" onsubmit="return sprawdz(this)"/> </center> </form> </div> </body> </html>
Plik rejestracja.js
function sprawdz (form){ var user=form.nazwa.value; if ((user.length<5) || (user.length>10)) { document.getElementById("zlaNazwa").innerHTML = "Nazwa użytkownika może mieć od 5 do 10 liter"; document.getElementById("zlaNazwa").className = "wyroznienieCzerwone"; form.nazwa.focus; return false; } else { document.getElementById("zlaNazwa").innerHTML = "";} if (form.haslo.value.length < 7) { document.getElementById("opisHasla").innerHTML = "Proszę wprowadzić hasło co najmniej 7 literowe."; document.getElementById("opisHasla").className = "wyroznienieCzerwone"; form.haslo.focus(); return false ; } if (!((user.match(/[a-z]/)) || (user.match(/[A-Z]/)))) { document.getElementById("zlaNazwa").innerHTML = "Nazwa użytkownika zawiera tylko litery"; document.getElementById("zlaNazwa").className = "wyroznienieCzerwone"; form.nazwa.focus; return false; } else { document.getElementById("zlaNazwa").innerHTML = ""; } if (form.haslo.value!=form.haslo2.value) { document.getElementById("zgodneHasla").innerHTML = "Hasła nie są zgodne!"; document.getElementById("zgodneHasla").className = "wyroznienieCzerwone"; return false; } return true;} function silaHasla( haslo ) { var punkty=0; if (haslo.length >=7) punkty++; if ((haslo.match(/[a-z]/)) && (haslo.match(/[A-Z]/))) punkty++; if (haslo.match(/\d+/)) punkty++; if (haslo.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) punkty++; if (punkty<1) { document.getElementById("opisHasla").innerHTML = "Bardzo słabe"; document.getElementById("opisHasla").className = "opisHaslaBardzoSlabe"} else if (punkty<2) { document.getElementById("opisHasla").innerHTML = "Słabe"; document.getElementById("opisHasla").className = "opisHaslaSlabe"} else if (punkty<3){ document.getElementById("opisHasla").innerHTML = "Średnie"; document.getElementById("opisHasla").className = "opisHaslaSrednie"} else { document.getElementById("opisHasla").innerHTML = "Silne"; document.getElementById("opisHasla").className = "opisHaslaSilne"} } return true; }
oraz plik: styleRej.css
body { font-family: Verdana; } #rejestr { width: 600px; background-color: #C3DBEA; border: 1px dotted #55BBFF; padding: 5px; margin: 0px auto; } div.row { clear: both; padding-top: 10px; } div.row span.label { float: left; width: 200px; text-align: right; padding-right: 5px; } div.row span.formw { float: right; width: 400px; text-align: left; } input { width: 200px; } .spacer { clear: both; } .wyroznienieCzerwone{ padding-left:10px; color:Red; font-weight:600; }