SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change colour of Select tag onChange()

    Hi,

    i have a select box as below.

    <select onChange="document...............">
    <option value="New">New</option>
    <option value="Old">Old</option>
    </select>

    onChange it filters the results by either New/Old. What i would like to do is to change the colour of the select box to show that an option has been selected. I.E after i select New the results are filtered and the select box changes colour.

    Is this possible?

  2. #2
    SitePoint Member
    Join Date
    Nov 2009
    Location
    North Carolina
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    This will do what you want:

    Code:
    <select onChange="this.style.background='#FFFF00';">
    <option value="New">New</option>
    <option value="Old">Old</option>
    </select>
    I tested this in IE8 and Chrome and it worked to change the color whenever the value changes. Change the color value to whatever you want the color to be. You could also put this into a JavaScript function and reuse for several inputs on a form. If you have any questions let me know.

    --Travis
    If I have been of help to you please consider making a
    donation for my time via PayPal here.
    Get a GREAT domain for under $20 each day via my
    STEAL of the DAY page.


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
  •