Computing.Net > Forums > Web Development > PHP/CSS -- border color

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP/CSS -- border color

Reply to Message Icon

Name: ryry1283
Date: February 19, 2006 at 18:08:47 Pacific
OS: Windows XP
CPU/Ram: not relevant
Product: not relevant
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: February 19, 2006 at 20:12:02 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: PHP/CSS -- border color

PHP image border www.computing.net/answers/webdevel/php-image-border/2255.html

php slide show in JS not working www.computing.net/answers/webdevel/php-slide-show-in-js-not-working/3906.html

firefox with css www.computing.net/answers/webdevel/firefox-with-css/765.html