javascript - Add CSS when there's an error -
i have simple login page i'm having trouble with. when type in incorrect info runs alert, want add css backgrounds of fields makes them red. how go editing following code this?
thanks.
<html> <head> <link rel="stylesheet" type="text/css" href="styles.css" /> <title>jeremy blazé</title> </head> <body> <div id="box"> <img src="logo.png" /> <form name="login"> <input type="text" name="userid" placeholder="username" /> <input type="password" name="pswrd" placeholder="password" /> <input type="submit" class="button" onclick="check(this.form)" placeholder="password" value="sign in" /> </form> </div> <script language="javascript"> function check(form) { if(form.userid.value == "username" && form.pswrd.value == "password") { window.open('dashboard/index.html') } else { alert("error password or username") } } </script> </body> </html>
// js else { alert("error password or username"); document.login.class = "error"; } // css form.error input[type="text"], form.error input[type="text"] { background-color: red; }
Comments
Post a Comment