Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I assistance writing code for a javascript array

    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?

  • #2
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I didn't want to do your work, but it seemed interesting. Is this what you were looking for?

    Code:
    <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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •