...

View Full Version : I assistance writing code for a javascript array



elogics
12-30-2003, 03:54 PM
I need assistance writing code for a javascript array in an asp page..
I have created a two-dimensional array that stores data from a database table. The array consists of the following fields.

emp_id, emp_name, supervisor, manager

var REPRELATE = new Array();
REPRELATE[0]= new Array("123456","Jones, Carol","Smith ,Michelle","Lesley,Patricia",);
REPRELATE[1]= new Array("126655","Hamelton, Denise","Hunter,Anne","Rose,Krista",);
REPRELATE[2]= new Array("127755","Cooper, Helen","Franks,Vicki","Edwards,Annika",);
REPRELATE[3]= new Array("127884","Howard, Elizabeth","Sharne,Avis","Preay,Darryl",);
REPRELATE[4]= new Array("127943","Jackson, Jill","Franks,Vicki","Edwards,Annika D",);

I want a drop down box that populates with the emp_name (using a recordset) then match the drop down selection with the same emp_name in the array.
Once the emp_name is selected from the drop down the emp_id value is passed to a hidden field and the supervisor and manager of the employee is automatically populated in text boxes "txtSup" and txtMan. Can you please assist with the code for what I am trying to do?

Oakendin
12-31-2003, 05:54 AM
I didn't want to do your work, but it seemed interesting. Is this what you were looking for?



<form name=theForm method=post>
<script language="JavaScript1.2" type="text/javascript">
var REPRELATE = new Array();
REPRELATE[0]= new Array("123456","Jones, Carol","Smith ,Michelle","Lesley,Patricia");
REPRELATE[1]= new Array("126655","Hamelton, Denise","Hunter,Anne","Rose,Krista");
REPRELATE[2]= new Array("127755","Cooper, Helen","Franks,Vicki","Edwards,Annika");
REPRELATE[3]= new Array("127884","Howard, Elizabeth","Sharne,Avis","Preay,Darryl");
REPRELATE[4]= new Array("127943","Jackson, Jill","Franks,Vicki","Edwards,Annika D");

document.write("<select name=\"employee\" onchange=\"updateSupMan(this)\"><option value=0>select a name");
for(i = 0; i < REPRELATE.length; i++) {
document.write("<option value=\"" + REPRELATE[i][0] + "\">" + REPRELATE[i][1]);
}
document.write("</select>");

function updateSupMan(field) {
var fieldValue = field.value;
document.theForm.txtSup.value = getManager(fieldValue);
document.theForm.txtMan.value = getSupervisor(fieldValue);
}

function getManager(fieldValue) {
var mangerName = "";
for(i = 0; i < REPRELATE.length; i++) {
if(fieldValue == REPRELATE[i][0]) {
mangerName = REPRELATE[i][3]
}
}
return mangerName;
}

function getSupervisor(fieldValue) {
var mangerName = "";
for(i = 0; i < REPRELATE.length; i++) {
if(fieldValue == REPRELATE[i][0]) {
mangerName = REPRELATE[i][2]
}
}
return mangerName;
}
</script>
<br><br>
<input type="text" name="txtSup" value="">&nbsp;&nbsp;<input type="text" name="txtMan" value="">
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum