 |
| Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 30th, 2003, 11:07 AM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
assistance writing code for a javascript arrray
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?
|
|

December 30th, 2003, 05:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
|
|
try the following approach, there are probably many more cleaner ways to do it:
<html>
<head>
<script language="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");
function addOption(whichDD,name,value)
{
// create a reference to the SELECT and the form
var theDD=eval(whichDD);
// create the new OPTION
var newOption;
newOption= new Option (name,value);
// position
var insertAt = theDD.options.length;
// create the space
theDD.options.length=theDD.options.length + 1;
// add the option
theDD.options[insertAt] = newOption;
}
function myDD_onChange()
{
// get the current value
var curIndex=document.myForm.myDD.value;
// populate the fields
document.myForm.txtSup.value=REPRELATE[curIndex][2];
document.myForm.txtMan.value=REPRELATE[curIndex][3];
document.myForm.empID.value=REPRELATE[curIndex][0];
}
function showDDElements()
{
// Display the name and use the value as the index for the array REPRELATE
for (count=0;count<REPRELATE.length;count++)
{
addOption(document.myForm.myDD,REPRELATE[count][1],count);
}
}
</script>
</head>
<body onload="showDDElements();">
<form name="myForm">
<select name="myDD" onchange="myDD_onChange()">
</select><br>
<input type="text" size="20" name="txtSup"><br>
<input type="text" size="20" name="txtMan"><br>
<input type="hidden" size="20" name="empID"><br>
</form>
</body>
</html>
|
|
 |