troubleshooting Question

JavaScript with drop down selection

Avatar of diecasthft01
diecasthft01 asked on
7 Comments1 Solution76 ViewsLast Modified:
Good morning all, I was hoping to get some help with some JavaScript I have. As its put together it works fine, but I need to do something else and not sure how to get there. I have a standard form that has two drop downs. On the first drop down, if a user picks a certain selection, then two text form fields will automatically fill in. That works as I need it to. However, what I would like to do is have the capability to have the user pick a selection from the second list and fill in those same text form fields. My idea here is that the first drop down would have a list of the most common selections, but then if the required selection is not in the first drop down, the user can pick it from the second drop down and fill in the same form fields as if picking a selection from the first. I tried just duplicating the code and calling it ChoiceA but that didn't work. I'm missing something.....Thanks!!

    <style type="text/css">

<script type="text/javascript">
var ids = new Array();
var use = new Array();
var ful = new Array();

ids[0] = "";
use[0] = "";
ful[0] = "";

ids[1] = 1;
use[1] = "a1";
ful[1] = "Arron";

ids[2] = 2;
use[2] = "b1";
ful[2] = "Bill";

ids[3] = 3;
use[3] = "c1";
ful[3] = "Charlie";
ids[4] = "";
use[4] = "";
ful[4] = "";

function Choice() {
              y = document.getElementById("selectUsers");

              document.getElementById("ids").value = ids[y.selectedIndex];
              document.getElementById("use").value = use[y.selectedIndex];
              document.getElementById("ful").value = ful[y.selectedIndex];

<form name="form1" method="post" action="">
<select id="selectUsers" name="users" onChange='Choice();'>
<option value="">Select</option>
<option value="1">a1</option>
<option value="2">b1</option>
<option value="3">c1</option>
<option value="4">More</option>
<select id="selectUsersAdd" name="usersNew" onChange='Choice();'>
<option value="">Select</option>
<option value="1">a2</option>
<option value="2">b2</option>
<option value="3">c2</option>
<p>ids <input type="text" id="ids" name="id" ></p>
<p>use <input type="text" id="use" name="username" ></p>
<p>ful <input type="text" id="ful" name="full_name" ></p>
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros