changing a textarea's bgcolor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    changing a textarea's bgcolor

    If you take a look at the textarea for commenting on this page you'll see my desire.

    When hovering over the textarea the bgcolor changes, but once the textarea is clicked it maintains this new color until the area loses focus.

    What's going on guys?

    Edit. I posted this in the wrong darn forum!
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    You can use the onMouseOver, onMouseOut, onFocus and onBlur events to do this.
    You will just have to create a JavaScript variable that indicates whether the input has focus. When it does, prevent the onMouseOut event from changing the color.

    Originally posted by markusn00b
    Edit. I posted this in the wrong darn forum!
    I'll move it over to the JavaScript forums.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Or better yet... The CSS :hover and :focus effects
      [code=css]
      textarea {
      background-color: #FFFFFF;
      }
      textarea:hover, textarea:focus {
      background-color: #FFFFCC;
      }
      [/code]
      Doesn't work in IE tho :(
      (Grrr @ M$)

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Well, its still in the wrong forum :p

        Use this css

        [code=css]textarea.effect , input.effect {
        background-color:#eeeeff;
        }
        textarea.effect :hover, input.effect:ho ver,textarea.ef fect:focus, input.effect:fo cus {
        background-color:#ffeeee;
        }[/code]

        where effect is the class name of the textareas and input boxes to whom you want to apply this.


        [EDIT].. I'm late.. already done by Atli :)

        Comment

        • Velhari
          New Member
          • Sep 2006
          • 46

          #5
          Originally posted by Atli
          Or better yet... The CSS :hover and :focus effects
          [code=css]
          textarea {
          background-color: #FFFFFF;
          }
          textarea:hover, textarea:focus {
          background-color: #FFFFCC;
          }
          [/code]
          Doesn't work in IE tho :(
          (Grrr @ M$)
          Hi,

          This code is working in IE on Strict Mode.

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Originally posted by Velhari
            Hi,

            This code is working in IE on Strict Mode.
            Strict Mode.. .... Strict Doctype?

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Originally posted by Velhari
              Hi,

              This code is working in IE on Strict Mode.
              I guess that would be IE7.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by Atli
                You can use the onMouseOver, onMouseOut, onFocus and onBlur events to do this.
                You will just have to create a JavaScript variable that indicates whether the input has focus. When it does, prevent the onMouseOut event from changing the color.
                CSS :hover pseudo-classes are not supported by IE7 unless a doctype is provided, so you will need to use JavaScript to achieve this (if you also need to support IE6).

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Thanks for all the responses guys!

                  They all, at a glance, are what I'm looking for.

                  Wasn't a major thing, just a query.

                  :)

                  Comment

                  • Biggaz1979
                    New Member
                    • Feb 2012
                    • 8

                    #10
                    This CSS code worked fine for me too in Chrome :)

                    Comment

                    Working...