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
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.

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.