Vzlotea
Vzlotea

Reputation: 97

Change the color of the "default" value of an input

I have this code ->

var searchexampletxt = '<?php echo JText::_('SEARCH_EXAMPLE'); ?>';
Window.onDomReady(function(){

$('BLA_BLA').addEvent('focus',function(){
    if(this.value=='<?php echo JText::_('SEARCH_EXAMPLE');?>')
    {
    this.value="";
        }
    });

$('BLA_BLA').addEvent('blur',function(){
    if(this.value=='')
    {
    this.value="<?php echo JText::_('SEARCH_EXAMPLE');?>";
        }
    }); 

});

Can somebody help me please, how can I make the "SEARCH_EXAMPLE" text (that is by default shown in inputbox) be for example color #CCCCCC, but the text that I'm writing in the inputbox be for example #333333 ??

Thank you Cheers

Upvotes: 0

Views: 596

Answers (1)

Victor
Victor

Reputation: 5769

Use this.style.color="red" or using hex-code this.style.color="#FF0000".

So, for your example:

  1. After this.value=""; add this.style.color="#CCCCCC";

  2. After this.value="<?php echo JText::_('SEARCH_EXAMPLE');?>" add this.style.color="#333333";

Upvotes: 2

Related Questions