SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    396
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Assigning onclick to a select box/option

    Hi,

    I've select list with a span right next to it (currently blank) that is going to update according to which of the options you select, for example, if the select box had the options 'blue', 'yellow' and 'red', I want to update the span to say 'The colour you have selected is red'. Obviously this is just an example and not the real purpose ;p

    The code I'm using is:

    document.getElementById('description').innerHTML = 'The colour you have selected is red';

    Which works just fine in Firefox, but in IE (which everyone here uses) it does nothing.

    I've tested it with an alert, and it seems even that doesn't work in IE, so I assume it's not registering the onclick function.

    Anyway around this please?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    How about the onchange event of the select element.

  3. #3
    SitePoint Addict
    Join Date
    Jun 2007
    Posts
    396
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can't access the files from here, but onchange sounds absolutely perfect, since if they were navigating with the keyboard it'd be reflected too, thank you!


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
  •