-2

I have an input variale text with the following attributes:

<input type="text" style="font-style: italic; color:#808080; font-size: 16px; width: 510px;" id="categ" value="default" name="categ" onfocus="this.value = ''; this.style.color='black'; this.font_weight='normal'">

i want to clear the formatting style onfocus. It clears the color and text but not the italics weight. I have also tried font-weight and font.weight

CodeMonkey
  • 2,226
  • 8
  • 45
  • 90
  • 2
    Sorry, but this is not a really good practice and will quickly lead to unmaintainable code... You should define a stylesheet and use the `:focus` selector. Javascript simply should NOT tinker with CSS properties. – kapa Mar 07 '13 at 00:51
  • Something like this ? .myDiv{ focus: "this.value = ''; this.style.color='black'; this.style.font.font_weight='normal'; } – CodeMonkey Mar 07 '13 at 00:56
  • No Javascript. CSS. Let me show you... Play with [this demo](http://jsfiddle.net/QgSxy/). – kapa Mar 07 '13 at 00:58
  • someone -1 ed this ? really ? – CodeMonkey Mar 07 '13 at 01:05

3 Answers3

2

You want font-weight:

this.style.fontWeight="normal"

A better way to do it is to use css:

#categ:focus{
    font-weight: normal;
    color:black;
}
#categ{
   font-style: italic; 
   color:#808080; 
   font-size: 16px; 
   width: 510px
}
Nix
  • 54,648
  • 29
  • 144
  • 196
1

if memory doesn't fail me..

this.style.fontWeight='normal'

however as bažmegakapa said in his comment - this is really bad practice. You should rather create a listener to the onfocus event - e.g. in jquery you could use the .focus() method - and have a callback function to update the css of your element.

Pure css would be even better!

Luca
  • 8,624
  • 5
  • 45
  • 57
1
this.style.fontWeight='normal'

update

this.style.fontStyle='normal'

Preview >> jsfiddle Update >> jsfiddle

madhushankarox
  • 1,369
  • 1
  • 12
  • 16