Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Sorry for the crappy title, but I wasn't sure how to describe it. I want to code something similar to a page found at http://www.funwithmovies.com, where you can enter text into a text box. The text box starts off with no colored border. Then once you start typing, it has a red border. Once you get it correct, the border turns green. Would the optimal way to do this be with CSS/PHP? I know the css would be simple enough. But would you need to set up a conditional (if-then-else) statement in PHP? I'm just wondering what the best way to go about doing this would be.
Thanks.

PHP is only used to process a page before it is sent to the client (i.e. visitor). After the page has been delivered, PHP can not have any control over what happens. So, it is not PHP in that page.
CSS could be *part* of the solution if you used it to create style classes that can be changed out. But it is not necessary.
The real key would be javascript.
Here is a one way to do it:
1. In the head of your document include this:
<script language="javascript">
function checkTitle(field,value) {
if (!field.value) {
// Default style
field.style.border = '1px solid #cecece';
} else {
if (field.value!=value) {
// Incorrect value
field.style.border = '2px solid #ff0000';
} else {
// Correct value
field.style.border = '2px solid #0000ff';
}
}
}
</script>Then in the input field add the following:
<input name="fieldName" onkeyup="checkTitle(this,'testing');">
Change the second value in the function call (i.e. 'testing') to the correct value for that field.
Michael J

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |