how to change font style of text in textbox on click?

noob picture noob · Sep 5, 2009 · Viewed 30.5k times · Source

how can i do this using javascript?

my textbox has a default value which is italic but when it is clicked the textbox will be cleared and the fontstyle should be normal.

Answer

Canavar picture Canavar · Sep 5, 2009

try something like that :

<input type="text" value="Enter user ID here" 
  style="font-style:italic;" 
  onfocus="this.value='';this.style.fontStyle='normal';" 
  onblur="clickrecall(this,'Enter user ID here');this.style.fontStyle='italic';">

EDIT : As we clear the format when user enters the textbox, we should set the fontStyle to italic back when he goes out.