Passing values between 2 drop down forms on the same page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamming
    New Member
    • Nov 2011
    • 9

    #1

    Passing values between 2 drop down forms on the same page

    I have 2 forms on a page. I need to take one of the values from a drop down menu on the first form then pass this value to the second form on the same page.


    Specifically I have 2 triple Drop Down (DD) menus.

    Code:
             ======DD2 =========DD3
             |
    DD1      |
             | 
             ======DD4 ========DD5
    I have
    DD1, DD2 and DD3 on one form
    and
    DD1, DD4 and DD5 on the other form

    I was getting too messed up merging them so I broke them into 2 forms. Each is working but I don't want the user to have to select DD1 twice on the same page.

    Thanks.
    Last edited by Dormilich; Nov 30 '11, 09:46 PM. Reason: added [code] [/code] tags for preserving whitespace
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the problem is that you can’t have one dropdown in two forms. what you may do is on selection of DD1 in one form updating a hidden field in the second form.

    Comment

    • jamming
      New Member
      • Nov 2011
      • 9

      #3
      Yes, I had to give DD1 different names. If I am using basically the same code, how would I pass the information to the hidden field? Thanks.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        you would have to use JavaScript for that. in the change event of the dropdown, just pass the value to the hidden field.
        Code:
        // the dropdown
        var sel = document.myform1.dd1;
        // the hidden field
        var hid = document.myform2.dd1;
        
        function pass_value()
        {
            document.myform2.dd1.value = this.value;
        }
        sel.addEventListener("change", pass_value, true);

        Comment

        • jamming
          New Member
          • Nov 2011
          • 9

          #5
          I couldn't get this to work. But I think I have a simple solution...in JavaScript, can I set different variables to the same element in js within the same form? For instance: can I set:
          Code:
          aMenu3=document.formTripleMenu.menuTopics 
          //and
          aMenu6=document.formTripleMenu.menuTopics

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            and what does that help you?

            Comment

            • jamming
              New Member
              • Nov 2011
              • 9

              #7
              I thought then that I could merge the code from the 2 forms, then have the 4 other DDMs as variables, with one common DDM1. The key would be if I could have 2 variables for the 1st DDM. Does this make sense?

              Comment

              • omerbutt
                Contributor
                • Nov 2006
                • 638

                #8
                if you need to make a set of collections from all the drop downs into one single DD then why dont you keep collecting the selected values and then populate a DD on runtime with javascript , i hope i am getting you right.
                regards,
                Omer Aslam

                Comment

                • jamming
                  New Member
                  • Nov 2011
                  • 9

                  #9
                  Originally posted by omerbutt
                  if you need to make a set of collections from all the drop downs into one single DD then why dont you keep collecting the selected values and then populate a DD on runtime with javascript , i hope i am getting you right.
                  regards,
                  Omer Aslam
                  No, I need 4 distinct drop downs, driven from one common DD. Think Regions, County, Towns as one set, an the other as Regions, Property Types and Property sub-Types. The Region DD is the same.

                  I have the code for the two sets now in two separate forms and js files because I was going insane. So now they are working. The logic is the same. So now I want to get rid of the need to ask for Region twice. Dormilich suggested I use the hidden input, but I couldn't get that working...so I then thought I would just merge the 2 forms AND merge the 2 js code since I kept a different set of variables for each js page. The only thing I need is to see if I can use the same parameters from Regions to drive 2 different branches.

                  Obviously, this is not working and I wanted to know if this was the problem :-(

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    the core question is, what of these DDs you need to submit in the end. if you only need to submit Town or Property sub-type it doesn’t matter where DD1 is.

                    according to your description it seem that you have something like a combo box (select from the first, then the next is auto populated (by AJAX) depending on the selected value and so on). in this case you just need to trigger the auto-populating for each of the next two DDs.

                    Comment

                    Working...