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. How to link two <select> elements?

How to link two <select> elements?

Scheduled Pinned Locked Moved Web Development
questiontutorial
8 Posts 4 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.
  • D Offline
    D Offline
    Diego F
    wrote on last edited by
    #1

    Hello. I'm not sure about how to do that. It seems simple. I have two elements that have two excluding values, A and B. What I need is that if I select A option in one, B is set in the other, and if I set B, the other is set with A. How can I do that? Regards, Diego F.

    V F G 3 Replies Last reply
    0
    • D Diego F

      Hello. I'm not sure about how to do that. It seems simple. I have two elements that have two excluding values, A and B. What I need is that if I select A option in one, B is set in the other, and if I set B, the other is set with A. How can I do that? Regards, Diego F.

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      http://www.java2s.com/Code/JavaScript/Form-Control/LinkedComboBoxoptionCountryprovince.htm[^]

      Vasudevan Deepak Kumar Personal Homepage Tech Gossips

      D 1 Reply Last reply
      0
      • V Vasudevan Deepak Kumar

        http://www.java2s.com/Code/JavaScript/Form-Control/LinkedComboBoxoptionCountryprovince.htm[^]

        Vasudevan Deepak Kumar Personal Homepage Tech Gossips

        D Offline
        D Offline
        Diego F
        wrote on last edited by
        #3

        Thank you, but I'm not sure if that is what I need. I find examples from one select loading another select. But I have two select that have the same two options, and any of them can be selected, so the other takes the other value.

        Regards, Diego F.

        V 1 Reply Last reply
        0
        • D Diego F

          Thank you, but I'm not sure if that is what I need. I find examples from one select loading another select. But I have two select that have the same two options, and any of them can be selected, so the other takes the other value.

          Regards, Diego F.

          V Offline
          V Offline
          Vasudevan Deepak Kumar
          wrote on last edited by
          #4

          Diego F. wrote:

          the other takes the other value.

          Meaning it should NOT be the same as the one in the first dropdown? You may need to actually iterate through the options array to achieve the same and unselect in case of violation?

          Vasudevan Deepak Kumar Personal Homepage Tech Gossips

          D 1 Reply Last reply
          0
          • D Diego F

            Hello. I'm not sure about how to do that. It seems simple. I have two elements that have two excluding values, A and B. What I need is that if I select A option in one, B is set in the other, and if I set B, the other is set with A. How can I do that? Regards, Diego F.

            F Offline
            F Offline
            Fred_Smith
            wrote on last edited by
            #5

            Is this what you're after? <!-- function s(a,b){ var sel1 = document.getElementById(a); var sel2 = document.getElementById(b); if (sel1.selectedIndex==0) { sel2.selectedIndex=1; } else { sel2.selectedIndex=0; } } //--> One Two One Two

            D 1 Reply Last reply
            0
            • V Vasudevan Deepak Kumar

              Diego F. wrote:

              the other takes the other value.

              Meaning it should NOT be the same as the one in the first dropdown? You may need to actually iterate through the options array to achieve the same and unselect in case of violation?

              Vasudevan Deepak Kumar Personal Homepage Tech Gossips

              D Offline
              D Offline
              Diego F
              wrote on last edited by
              #6

              What I need is that: select1: options A and B select2: options A and B Select1 is set to A --> Select2 is set to B Select1 is set to B --> Select2 is set to A Select2 is set to A --> Select1 is set to B Select2 is set to B --> Select1 is set to A Maybe the above explanation wasn't clear enough.

              Regards, Diego F.

              1 Reply Last reply
              0
              • F Fred_Smith

                Is this what you're after? <!-- function s(a,b){ var sel1 = document.getElementById(a); var sel2 = document.getElementById(b); if (sel1.selectedIndex==0) { sel2.selectedIndex=1; } else { sel2.selectedIndex=0; } } //--> One Two One Two

                D Offline
                D Offline
                Diego F
                wrote on last edited by
                #7

                Yes! Thank you a lot!

                Regards, Diego F.

                1 Reply Last reply
                0
                • D Diego F

                  Hello. I'm not sure about how to do that. It seems simple. I have two elements that have two excluding values, A and B. What I need is that if I select A option in one, B is set in the other, and if I set B, the other is set with A. How can I do that? Regards, Diego F.

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  Using select controls for that doesn't really seem to make an intuitive interface. I would suggest that you just make two radio buttons which represent the A,B and B,A options.

                  --- single minded; short sighted; long gone;

                  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