Jump to content

Invalid user data highlighted


pxxb

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/282646-invalid-user-data-highlighted/
Share on other sites

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.

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.