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?

here's fiddle.

thanks.

<html> <head>     <link rel="stylesheet" type="text/css" href="styles.css" />     <title>jeremy blaz&eacute;</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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -