Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. change the index position in dropdown

change the index position in dropdown

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
tutorialdatabasehelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jaraldumary
    wrote on last edited by
    #1

    Hi, How to change the index position of dropdown list,for example if i select 2nd index value of dropdown ,after showing the result again it moves to 0th index , i want it to be remain in 2nd index value... need help.

    F 1 Reply Last reply
    0
    • J jaraldumary

      Hi, How to change the index position of dropdown list,for example if i select 2nd index value of dropdown ,after showing the result again it moves to 0th index , i want it to be remain in 2nd index value... need help.

      F Offline
      F Offline
      fly904
      wrote on last edited by
      #2

      Before the page has been loaded, use the selected attribute.

      Not Selected
      Also Not Selected
      Selected
      

      If you want it during run time; then use javascript.

      document.getElementById('selectbox').selectedIndex = 2;

      If at first you don't succeed, you're not Chuck Norris.

      J 1 Reply Last reply
      0
      • F fly904

        Before the page has been loaded, use the selected attribute.

        Not Selected
        Also Not Selected
        Selected
        

        If you want it during run time; then use javascript.

        document.getElementById('selectbox').selectedIndex = 2;

        If at first you don't succeed, you're not Chuck Norris.

        J Offline
        J Offline
        jaraldumary
        wrote on last edited by
        #3

        Thanks for your fast reply,I want the dropdown index should be changed during runtime,I dont want to assign the static value as 2, For the next if i select 3, then it will still remain in 2, I want the index to be changing as per user input.

        F 1 Reply Last reply
        0
        • J jaraldumary

          Thanks for your fast reply,I want the dropdown index should be changed during runtime,I dont want to assign the static value as 2, For the next if i select 3, then it will still remain in 2, I want the index to be changing as per user input.

          F Offline
          F Offline
          fly904
          wrote on last edited by
          #4

          It was just an example. Obviously you would put it in a function.

          function changeSelectedIndex(id, index)
          {
          document.getElementById(id).selectedIndex = index;
          }

          changeSelectedIndex('selectbox', n);

          Obviously, n can be any index (number) of your choice.

          If at first you don't succeed, you're not Chuck Norris.

          J 1 Reply Last reply
          0
          • F fly904

            It was just an example. Obviously you would put it in a function.

            function changeSelectedIndex(id, index)
            {
            document.getElementById(id).selectedIndex = index;
            }

            changeSelectedIndex('selectbox', n);

            Obviously, n can be any index (number) of your choice.

            If at first you don't succeed, you're not Chuck Norris.

            J Offline
            J Offline
            jaraldumary
            wrote on last edited by
            #5

            HI, Make a bit clear,changeSelectedIndex('selectbox', n); the 'n' is user choice or it changes dynamically at runtime.I want the index should be changed dynamically at runtime.I dont want to edit in code.

            F 1 Reply Last reply
            0
            • J jaraldumary

              HI, Make a bit clear,changeSelectedIndex('selectbox', n); the 'n' is user choice or it changes dynamically at runtime.I want the index should be changed dynamically at runtime.I dont want to edit in code.

              F Offline
              F Offline
              fly904
              wrote on last edited by
              #6

              Well I don't know how you're calling the index change so all I can do is put a variable there!

              If at first you don't succeed, you're not Chuck Norris.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups