Can I use PHP to change the color of a text field when the user clicks it?
If you have a HTML form and have a text field that when the user clicks on this so that its the one which the user can input data in is there a way of PHP changing the color of the background of the text field?
I would like to find a solution designed in PHP.
If it is possible can someone please provide some example code and an explanation on why it works?
Thanks!!
Re: Can I use PHP to change the color of a text field when the user clicks it?
PHP is a server-side language. The onclick event is on the client-side. Using PHP would be a ridiculous implementation because it would require client-side scripting to communicate with the server-side PHP and then the server-side PHP would have to tell the client-side to change the color.
All that to say...use the client-side!
Code:
<textarea ... onclick="this.style.background='#ffff00';"></textarea>
Re: Can I use PHP to change the color of a text field when the user clicks it?
Quote:
Originally Posted by
PeejAvery
PHP is a server-side language. The
onclick event is on the client-side. Using PHP would be a ridiculous implementation because it would require client-side scripting to communicate with the server-side PHP and then the server-side PHP would have to tell the client-side to change the color.
All that to say...use the client-side!
Code:
<textarea ... onclick="this.style.background='#ffff00';"></textarea>
Actually you will get better speed out of change the class name and letting CSS change the style then the change the style direct (except in opera), but again a client side issue.
http://www.quirksmode.org/dom/classchange.html
Re: Can I use PHP to change the color of a text field when the user clicks it?
Quote:
Originally Posted by
Roguebfl
Actually you will get better speed out of change the class name and letting CSS change the style then the change the style direct (except in opera), but again a client side issue.
Yes and no. If you are changing multiple styles of the element, then yes. But, changing just the background, there's really no speed difference. In this case, if you're just changing the color, it would be more work and page load time to have two extra defined classes in the stylesheets.
Re: Can I use PHP to change the color of a text field when the user clicks it?
Why does this CSS not work?
I want to change the background color when the user clicks a input field and not all input fields on my form. I want to complete all of this using an external style sheet.
I created some css but its not working! - any ideas on how to accomplish this using external style sheets?
here is the css code :
Code:
.form
{
input:focus
{
background-color:#FF6666
}
}
here is the html code:
Code:
<html>
<link href="form.css" rel="stylesheet" type="text/css">
<body>
<table cols="2">
<form name="form1">
<tr>
<td class=form><input name="txtName" size="30" class="form"></td>
</tr>
<tr>
<td> <input name="txtSpace" size="30"> </td>
</tr>
</form>
</table>
</body>
</html>
Re: Can I use PHP to change the color of a text field when the user clicks it?
Re: Can I use PHP to change the color of a text field when the user clicks it?
Your CSS tags are improperly nested.
Re: Can I use PHP to change the color of a text field when the user clicks it?
Code:
.form input:focus
{ background-color:#FF6666; }
Re: Can I use PHP to change the color of a text field when the user clicks it?
And here goes a complete solution how to change attached css dynamically: http://www.alistapart.com/articles/alternate/