View Full Version : how to change php input text boxes font color

12-02-2010, 04:25 AM
hi again

i have a couple of input text boxes

initially value of text boxes equal to 0 .......

what i want to do is if the textbox value equal to 0 font color should be white

if the textbox value not equal to o font color should be black

how do i do this ...
plz give me a sample code for this

12-02-2010, 06:40 AM
as someone fills in the form ? that would be a javascript question
if not then where is the current value of the field held ?

<input style="color:<?$value==0 ? 'white' : 'black';?>" value="<?=$value;?>" id="etc" name="etc">

12-02-2010, 07:02 AM
you can use jquery pretty easy with this, will do it live as you type or on load.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

var zero = $("#something").val();
if(zero == "0"){
$("#something").css("color", "white");
} else {
$("#something").css("color", "black");


<input type="text" name="something" id="something" style="color:white;" />

test it here: http://blueicestudios.com/dealers/test.php

12-02-2010, 10:06 AM
...or without jquery

function blah(obj){

<input type="text" name="something" id="something" style="color:white;" onkeyup="blah(this)" value="blah" />

.. or with vbscript ;) , but this is the PHP forum~