programmatically select an option in dropdown

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balu435
    New Member
    • Jan 2007
    • 13

    programmatically select an option in dropdown

    Hi friends,

    I have an (VBA) application which programatically fills the options in a web page.
    I have an dropdown menu whose options are selected during run-time by using a function.Is there anyway by which I can select the option in the dropdown menu programatically ?
    If the dropdown menu had its options explicitily mentioned (like <option value="1">1</option>...) I could have used document.form.o bjectname.selec tedindex=n
    But here all I have is a function to generate the values in the dropdown menu.
    <select name="name" id= "">
    print_month_ele ment_drop_down_ menu(1, 12, 2, ' ');
    </select>
    Is there a wayout to select the desired value programmaticall y?

    (I am temporarily using the sendkeys method,but it isnt that gr8 a solution...:-))

    Regards,
    Balu435
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    i think u r using VB ...

    so u better to look for VB forum

    Comment

    • dorinbogdan
      Recognized Expert Contributor
      • Feb 2007
      • 839

      #3
      To get a reference to the selected item, you can use this method:
      [HTML]var dropdown = document.getEle mentById("dropd ownId");
      var item = dropdown[dropdown.select edIndex];
      [/HTML]

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Also, don't forget to set the id for your dropdown. It is currently empty.

        Comment

        • balu435
          New Member
          • Jan 2007
          • 13

          #5
          Originally posted by acoder
          Also, don't forget to set the id for your dropdown. It is currently empty.
          hi,
          I am writing the code in VBA and the dropdown menu is in an external web page..
          I cant fiddle with the HTML code there...
          I have submitted the query in VB forum as well..
          Thanx for your help..
          Balu435

          Comment

          • balu435
            New Member
            • Jan 2007
            • 13

            #6
            Originally posted by balu435
            hi,
            I am writing the code in VBA and the dropdown menu is in an external web page..
            I cant fiddle with the HTML code there...
            I have submitted the query in VB forum as well..
            Thanx for your help..
            Balu435
            Hi..
            Its working now..
            I gave the code as document.form.o bject.selectedi ndex.=n
            where n is the index of the required value..
            I dont understand if it can get so simple..anyway its working..:-)

            Comment

            Working...