Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set values of multiple fields with one drop down selection

    Basically what I need to do is set value of 2 hidden fields based on the selection of the drop down.

    My situation is that I need to set a Cost Center Code and specify an Authorizing Manager based on the region the user selects from a drop down.

    I'd prefer not to use a bunch of 'if' statements, but I don't know how else I can do this.

    Does anyone have any ideas?

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Canada, eh?
    Posts
    133
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Use an array within an array to control which value was selected.

    Code:
    <script type="text/javascript">
    ops = new Array();
    ops[1] = new Array(45,32);
    ops[2] = new Array(12.5,409);
    ops[3] = new Array("some text","some other text.");
    
    function setvals(a) {
      if (typeof(ops[a]) == "undefined") return false;
      v1 = document.getElementById('hidden1');
      v2 = document.getElementById('hidden2');
      v1.value = ops[a][0];
      v2.value = ops[a][1];
    
      // Delete this alert if you actually use this code:
      alert('Hidden field 1 = '+v1.value+'\n\nHidden field 2 = '+v2.value);
    }
    </script>
    
    <form action="..." method="...">
    <input type="hidden" name="hidden1" id="hidden1" value="">
    <input type="hidden" name="hidden2" id="hidden2" value="">
    Select an option: <select name="the_select" id="the_select" onchange="setvals(this.selectedIndex);">
    <option>-Pick one-
    <option>#1
    <option>#2
    <option>#3
    </select>
    </form>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •