views:

847

answers:

2

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.

A: 

set the style in javascript method:

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

techzen
+1  A: 

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
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
onblur="this.value='';this.style.fontStyle='';" - to solve that issue
yoda
onblur="clickrecall(this,'Enter user ID here');this.value='';this.style.fontStyle='';"this doesn't seem to work.
noob