3

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.

noob
  • 4,699
  • 10
  • 33
  • 32

3 Answers3

4

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.

Canavar
  • 47,715
  • 17
  • 91
  • 122
  • thanks for the fast reply. when i tried this the text is italic in default and when clicked the font style turns to normal but there's a problem. in my textbox the default text is restored when nothing is typed in the textbox. when the default text is restored the font style becomes normal. it should still be in italic. – noob Sep 05 '09 at 18:00
  • onblur="this.value='';this.style.fontStyle='';" - to solve that issue – yoda Sep 05 '09 at 18:07
  • onblur="clickrecall(this,'Enter user ID here');this.value='';this.style.fontStyle='';" this doesn't seem to work. – noob Sep 05 '09 at 18:19
2
document.getElementById(inputId).style.fontStyle="normal";
bluish
  • 26,356
  • 27
  • 122
  • 180
Antonio
  • 21
  • 1
1

set the style in javascript method:

document.getElementById('test').style="font-style:normal;"

techzen
  • 2,895
  • 2
  • 22
  • 22