Hallo Community,
ich möchte die Prüfung eines Passwortes (zu Lernzwecken) mit folgendem Script realisieren:
Wenn man etwas in das Textfeld eingibt (bei onkeypress), wird die Funktion check() aufgerufen, welche prüfen soll, ob das Passwort korrekt ist. Bei Übereinstimmung soll das Textfeld grün, bei Unterschied rot und bei fehlender Eingabe ('') weis eingefärbt werden. Leider färbt es sich, sobald ich eine Taste drücke für immer rot, d.h. es wird bei korrekter Eingabe des Passworts nicht grün. Wo liegt mein Denkfehler?
ich möchte die Prüfung eines Passwortes (zu Lernzwecken) mit folgendem Script realisieren:
Code:
[SIZE=2][COLOR=#0000f0][SIZE=2][COLOR=#0000f0][COLOR=black]<!DOCTYPE[/COLOR][/COLOR][/SIZE][/COLOR][/SIZE][COLOR=black][SIZE=2][SIZE=2]HTML[/SIZE][/SIZE][SIZE=2][SIZE=2]PUBLIC[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]"-//W3C//DTD HTML 4.0 Transitional//EN">[/COLOR][/SIZE]
[SIZE=2][COLOR=black]<html>[/COLOR][/SIZE]
[/SIZE][SIZE=2][SIZE=2][COLOR=black]<head>[/COLOR][/SIZE]
[/SIZE][SIZE=2][SIZE=2][COLOR=black]<script type="text/javascript">[/COLOR][/SIZE]
[/SIZE][SIZE=2][COLOR=black]function check[/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=black]()[/COLOR][/SIZE][/SIZE][SIZE=2][COLOR=black] {[/COLOR][/SIZE]
[SIZE=2][COLOR=black]var password [/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=black]=[/COLOR][/SIZE][/SIZE][SIZE=2][COLOR=black] [I]"blabla"[/I];[/COLOR][/SIZE]
[SIZE=2][COLOR=black]var feed [/COLOR][/SIZE][COLOR=black][SIZE=2][SIZE=2]=[/SIZE][/SIZE][SIZE=2] document[/SIZE][SIZE=2][SIZE=2].[/SIZE][/SIZE][SIZE=2]getElementById[/SIZE][SIZE=2][SIZE=2]([/SIZE][/SIZE][SIZE=2]'feed'[/SIZE][SIZE=2][SIZE=2])[/SIZE][/SIZE][/COLOR][SIZE=2][COLOR=black];[/COLOR][/SIZE]
[SIZE=2][COLOR=black]if[/COLOR][/SIZE][COLOR=black][SIZE=2][SIZE=2]([/SIZE][/SIZE][SIZE=2]password [/SIZE][SIZE=2][SIZE=2]==[/SIZE][/SIZE][SIZE=2] feed[/SIZE][SIZE=2][SIZE=2])[/SIZE][/SIZE][/COLOR][SIZE=2][COLOR=black] {[/COLOR][/SIZE]
[SIZE=2][COLOR=black]document[/COLOR][/SIZE][COLOR=black][SIZE=2][SIZE=2].[/SIZE][/SIZE][SIZE=2]getElementById[/SIZE][SIZE=2][SIZE=2]([/SIZE][/SIZE][SIZE=2]'password'[/SIZE][SIZE=2][SIZE=2]).[/SIZE][/SIZE][SIZE=2]style[/SIZE][SIZE=2][SIZE=2].[/SIZE][/SIZE][SIZE=2]backgroundColor [/SIZE][SIZE=2][SIZE=2]=[/SIZE][/SIZE][/COLOR][SIZE=2][COLOR=black] 'green';[/COLOR][/SIZE]
[SIZE=2][COLOR=black]} [/COLOR][/SIZE]
[SIZE=2][COLOR=black]else if[/COLOR][/SIZE][COLOR=black][SIZE=2][SIZE=2]([/SIZE][/SIZE][SIZE=2]feed [/SIZE][SIZE=2][SIZE=2]==[/SIZE][/SIZE][SIZE=2] ''[/SIZE][SIZE=2][SIZE=2])[/SIZE][/SIZE][/COLOR][SIZE=2][COLOR=black] {[/COLOR][/SIZE]
[SIZE=2][COLOR=black]document[/COLOR][/SIZE][COLOR=black][SIZE=2][SIZE=2].[/SIZE][/SIZE][SIZE=2]getElementById[/SIZE][SIZE=2][SIZE=2]([/SIZE][/SIZE][SIZE=2]'password'[/SIZE][SIZE=2][SIZE=2]).[/SIZE][/SIZE][SIZE=2]style[/SIZE][SIZE=2][SIZE=2].[/SIZE][/SIZE][SIZE=2]backgroundColor [/SIZE][SIZE=2][SIZE=2]=[/SIZE][/SIZE][/COLOR][SIZE=2][COLOR=black] 'white';[/COLOR][/SIZE]
[SIZE=2][COLOR=black]} [/COLOR][/SIZE]
[SIZE=2][COLOR=black]else {[/COLOR][/SIZE]
[SIZE=2][COLOR=black]document[/COLOR][/SIZE][COLOR=black][SIZE=2][SIZE=2].[/SIZE][/SIZE][SIZE=2]getElementById[/SIZE][SIZE=2][SIZE=2]([/SIZE][/SIZE][SIZE=2]'password'[/SIZE][SIZE=2][SIZE=2]).[/SIZE][/SIZE][SIZE=2]style[/SIZE][SIZE=2][SIZE=2].[/SIZE][/SIZE][SIZE=2]backgroundColor [/SIZE][SIZE=2][SIZE=2]=[/SIZE][/SIZE][/COLOR][SIZE=2][COLOR=black] 'red';[/COLOR][/SIZE]
[SIZE=2][COLOR=black]}[/COLOR][/SIZE]
[SIZE=2][COLOR=black]}[/COLOR][/SIZE]
[SIZE=2][SIZE=2][COLOR=black]</script>[/COLOR][/SIZE]
[/SIZE][SIZE=2][SIZE=2][COLOR=black]<title>[/COLOR][/SIZE][/SIZE][SIZE=2][COLOR=black]Passwortpr[I]ü[/I][/COLOR][COLOR=black];fung[/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=black]</title>[/COLOR][/SIZE]
[SIZE=2][COLOR=black]<meta [/COLOR][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]http[/SIZE][/SIZE][SIZE=2]-[/SIZE][SIZE=2][SIZE=2]equiv[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"content-type" [/SIZE][/SIZE][SIZE=2][SIZE=2]content[/SIZE][/SIZE][SIZE=2]=[/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]"text/html; charset=iso-8859-1">[/COLOR][/SIZE]
[SIZE=2][COLOR=black]</head>[/COLOR][/SIZE]
[SIZE=2][COLOR=black]<body>[/COLOR][/SIZE]
[/SIZE][COLOR=black][SIZE=2][SIZE=2]<form [/SIZE][/SIZE][SIZE=2][SIZE=2]action[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"password.html" [/SIZE][/SIZE][SIZE=2][SIZE=2]method[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"post">[/SIZE][/SIZE][/COLOR]
[COLOR=black][SIZE=2][SIZE=2]<input [/SIZE][/SIZE][SIZE=2][SIZE=2]type[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"text" [/SIZE][/SIZE][SIZE=2][SIZE=2]name[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"password" [/SIZE][/SIZE][SIZE=2][SIZE=2]id[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"feed" [/SIZE][/SIZE][SIZE=2][SIZE=2]onkeypress[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"check()">[/SIZE][/SIZE][/COLOR]
[COLOR=black][SIZE=2][SIZE=2]<input [/SIZE][/SIZE][SIZE=2][SIZE=2]type[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"submit" [/SIZE][/SIZE][SIZE=2][SIZE=2]name[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"submit" [/SIZE][/SIZE][SIZE=2][SIZE=2]value[/SIZE][/SIZE][SIZE=2]=[/SIZE][SIZE=2][SIZE=2]"Prüfen">[/SIZE][/SIZE][/COLOR]
[SIZE=2][SIZE=2][COLOR=black]</form>[/COLOR][/SIZE][/SIZE]
[SIZE=2][SIZE=2][COLOR=black]</body>[/COLOR][/SIZE]
[SIZE=2][COLOR=black]</html[/COLOR][/SIZE][/SIZE][SIZE=2][COLOR=black]>[/COLOR][/SIZE]