Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy info with javascript

Status
Not open for further replies.

DataSpy

Technical User
Nov 15, 2002
39
0
0
US
I found a tutorial on how to copy form values from one input box to another with a check box. What I want to do is copy info from an id using a drop down menu depending on which set of information I want to copy to an input box. Does anybody have any suggestions or a tutorial they'd recommend?

The tutorial I read is @


Any help greatly apprenticed, thanks in advance!!!
 
Where are you storing these sets of information?

The basic idea is more or less the same, the only difference is where you are getting the information from.

Personally I would use an array if there isn't a whole lot of information to keep. If you are looking at anything over say 10 sets, then a different approach may be necessary. Such as an Ajax connection to a DB or something similar.

For the array approach:

You'll want to populate your array with the relevant information, and then use the dropdown's onchange event to call your populating function to get the data from the array.

Code:
var infoArray = new Array();
var infoArray['id1'] =  new Array();
var infoArray['id1']['name'] = "Name1";
var infoArray['id1']['age'] = "40";

var infoArray['id2'] =  new Array();
var infoArray['id2']['name'] = "Name2";
var infoArray['id2']['age'] = "20";

var infoArray['id3'] =  new Array();
var infoArray['id3']['name'] = "Name3";
var infoArray['id3']['age'] = "30";
...


function populate(f,dropdown){

f.namefield.value = infoArray[dropdown.value]['name'];
f.agefield.value = infoArray[dropdwon.value]['age'];

}

HTML:
...
<select onchange="populate(this.form,this);">
<option value="id1">ID One</option>
<option value="id2">ID Two</option>
<option value="id3">ID Three</option>
<option value="id4">ID Four</option>
...
</select>


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top