SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    is craving 'the potato' slayerment's Avatar
    Join Date
    Nov 2002
    Location
    Scottsdale, Arizona, USA
    Posts
    603
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question: Changing input color on click

    I'm wanting to change an input field's color when you click on it, and then reset it back to normal if you click outside of it. Would anybody be able to tell me or point me in the way of an article?

    Thanks much .

  2. #2
    SitePoint Zealot cmorbutts's Avatar
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this to change the color of the input field...

    Code:
    <input type="text" id="fmName" onfocus="chgBgColor(this") onblur="resetBgColor(this)" />
     
    <script type="text/javascript">
    <!--
    function chgBgColor(objInput)
    {
    	objInput.style = "background-color: red";
    	
    	// or you could set objInput.className to a css class instead
    }
     
    function resetBgColor(objInput)
    {
    	objInput.style = "";
    	
    	// or you could set objInput.className to a css class instead
    
    }
    //-->
    </script>
    I would use css classes if I were you. If using "this" as an input into the function doesn't work, you could suppy the input id instead and change its properties with getElementById in javascript.

  3. #3
    is craving 'the potato' slayerment's Avatar
    Join Date
    Nov 2002
    Location
    Scottsdale, Arizona, USA
    Posts
    603
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks much, that did it for me .

  4. #4
    SitePoint Zealot cmorbutts's Avatar
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good stuff!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •