Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    122
    Thanks
    6
    Thanked 0 Times in 0 Posts

    how to change php input text boxes font color

    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

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,051
    Thanks
    10
    Thanked 94 Times in 92 Posts
    as someone fills in the form ? that would be a javascript question
    if not then where is the current value of the field held ?

    PHP Code:
    <input style="color:<?$value=='white' 'black';?>" value="<?=$value;?>" id="etc" name="etc">
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    you can use jquery pretty easy with this, will do it live as you type or on load.

    Code:
    <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() {
    						   
    	$("#something").keyup(function(){
    		var zero = $("#something").val();
    		if(zero == "0"){
    		  $("#something").css("color", "white");
    	    } else {
    		  $("#something").css("color", "black");
    	    }						 
    	});
    
    });
    </script>
    Code:
    <input type="text" name="something" id="something" style="color:white;" />
    test it here: http://blueicestudios.com/dealers/test.php
    Last edited by seco; 12-02-2010 at 10:26 AM.

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,051
    Thanks
    10
    Thanked 94 Times in 92 Posts
    ...or without jquery
    Code:
    <script>
    function blah(obj){
    	obj.value==0?obj.style.color="white":obj.style.color="black";
    }
    </script>
    
    <input type="text" name="something" id="something" style="color:white;" onkeyup="blah(this)" value="blah" />
    .. or with vbscript , but this is the PHP forum~
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •