asked on
<html>
<head>
<style type="text/css">
</style>
<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];
}
</script>
</head>
<body>
<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>
<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>
</select>
<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>
</form>
</body>
</html>
ASKER
I'm sorry....that didn't change anything for meDo you mean
So lets say 'selectUsers' has a list of names, and if a user selects ids2 from 'selectUsers' he will get the name "Bill" loaded in the form field box.I think I get this - it is what it is currently doing right?
But on 'selectUsersAdd' that dropdown may have a name, lets say Fred. I want to have Freds info populate the form field. But I don't know how to have Freds info listed as a variable since it comes from a different select form.This is not clear at all.
...that dropdown may have a name, lets say FredExcept it doesn't, it as a2, b2, c2 - if you can keep your descriptions tied to your actual code it might help. Remember this is clear to you because you have all the pieces of the puzzle - don't confuse the issue by introducing things that have not been clarified. Fred is not an option anywhere so don't let's use it.
ASKER
ids: 1
use: a1
ful: Aaron
Select c2 from list 2 (right)ids: 3
use: c1
ful: Charlie
ASKER
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY
Select 1
Open in new window
Select 2Open in new window
Both call Choice(), but in Choice ... you have thisOpen in new window
y is now select 1 irrespective of which select triggered the event.Let's change this. Lets make it that Choice() gets passed the relevant select
Open in new window
Now all we need to do is pass in the correct select for each changeSelect 1Open in new window
Select 2Open in new window
That should work for now - but if you change your id's so that a select has more options than are in the array you will have to do some bounds checking to make sure you don't reference an array item that does not exist.