Selecting and item in a dropdown box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erittaf
    New Member
    • Jan 2008
    • 5

    Selecting and item in a dropdown box

    Let's assume I have a website with a dropdown box on it. there are 3 items in it;

    1 - red
    2 - blue
    3 - green

    Is there a javascript function that I could run make the selected item change to a certain item?

    Psuedocode:
    javascript:docu ment.form[0].element[0].select[green]
    or
    javascript:docu ment.form[0].element[0].select[3rdItem]

    not sure if it's possible and I'm really sure these don't work, just don't know the syntax well enough to make it go. I believe the underlined portions are definitely wrong... can someone help?
  • Death Slaught
    Top Contributor
    • Aug 2007
    • 1137

    #2
    Yeah go here.

    ^_^ Hope it helps, Thanks, Death

    Comment

    • erittaf
      New Member
      • Jan 2008
      • 5

      #3
      well i read through that link and i'm not sure what to use. It seems that is instructions for how to code a page. I want a bookmarklet that I can paste into my address bar that will change which item is in the dropdown box. The linked page says that the user needs to input. I want to automate that input. Is that possible?

      also would it be possible to do this by form/element/desired option number?

      Comment

      • Death Slaught
        Top Contributor
        • Aug 2007
        • 1137

        #4
        I think you can automate it, but i'm not sure how.

        I though you wanted to be able to erase an option and then replace it with something else. Sense that's not it I can't really help you much, someone will though.

        ^_^ Thanks, Death

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          You're looking for the selectedIndex property. Set that to the index of the select box - starting from 0.

          Comment

          • erittaf
            New Member
            • Jan 2008
            • 5

            #6
            javascript:docu ment.form[0].element[0].selectedindex( 0)
            javascript:docu ment.form[0].element[0].selectedindex[1]

            neither work... it's close to the right code but it doesn't work.
            BTW i need a bookmarklet (able to paste it in the address bar, hit enter and see the change happen.

            thanks for any input you may have!

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              That would be:
              [code=javascript]javascript:docu ment.forms[0].elements[0].selectedIndex= 0[/code]Note the case - JavaScript is case-sensitive.

              Comment

              Working...