pxxb Posted October 2, 2013 Share Posted October 2, 2013 I have a program that lets the user type in the year and if the year is not numeric or isn't 4 digits it will display an error when user presses submit. I am wondering, how would I make it so the text box gets highlighted if the user types an invalid year? I know it's done through css but that's about all. thanks. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 2, 2013 Share Posted October 2, 2013 How does your thing work? AJAX? Regular form submission? How do you determine there's an error? How do you pass along the error message? Need to know more. As for the highlighting itself, highlighted how? CSS's background, border, and/or outline properties are probably what you're looking for. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 2, 2013 Share Posted October 2, 2013 Just use a different CSS style for the fields with an error <html> <head> <style type="text/css"> input[type='text'].error { background-color: #FF0000; color: white; } </style> </head> <body> <form method="get"> Year: <input type="text" name="text" value="2013" size="6"> <br> Year: <input class='error' type="text" name="text" value="2o13" size="6"> <br> <input type="submit" name="btn" value="submit" class="error"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.