A Looping Array Lookup : Array « Language Basics « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Language Basics » Array 
A Looping Array Lookup

/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

John Wiley & Sons CopyRight 2001
*/


<HTML>
<HEAD>
<TITLE>Parallel Array Lookup II</TITLE>
<SCRIPT LANGUAGE="JavaScript">
// the data
var regionalOffices = new Array("New York""Chicago""Houston""Portland"
var regionalManagers = new Array("Shirley Smith""Todd Gaston""Leslie Jones""Harold Zoot"
var regOfficeQuotas = new Array(300000250000350000225000
// do the lookup into parallel arrays
function getData(form) { 
    // make a copy of the text box contents
    var inputText = form.officeInp.value 
    // loop through all entries of regionalOffices array
    for (var i = 0; i < regionalOffices.length; i++) { 
        // compare uppercase versions of entered text against one entry 
        // of regionalOffices
        if (inputText.toUpperCase() == regionalOffices[i].toUpperCase()) { 
            // if they're the same, then break out of the for loop 
            break 
        
    
    // make sure the i counter hasn't exceeded the max index value
    if (i < regionalOffices.length) { 
        // display corresponding entries from parallel arrays
        form.manager.value = regionalManagers[i
        form.quota.value = regOfficeQuotas[i
    else {  // loop went all the way with no matches
        // empty any previous values
        form.manager.value = "" 
        form.quota.value = "" 
        // advise user
        alert("No match found for " + inputText + "."
    


</SCRIPT>
</HEAD>
<BODY>
<H1>Parallel Array Lookup II</H1>
<HR>
<FORM NAME="officeData"
<P> 
Enter a regional office: 
<INPUT TYPE="text" NAME="officeInp" SIZE=35
<INPUT TYPE="button" VALUE="Search" onClick="getData(this.form)">
</P><P> 
The manager is: 
<INPUT TYPE="text" NAME="manager" SIZE=35
<BR> 
The office quota is: 
<INPUT TYPE="text" NAME="quota" SIZE=8
</P> 
</FORM> 
</BODY>
</HTML>

           
       
Related examples in the same category
1. Demo all methods in Array
2. Assing array value inside function
3. Simple Array Demo
4. Array loop, find:Control array : Two dimension array
5. Reversing, Sorting, and Concatenating an Array
6. Custom Numeric Comparison for the Array.Sort Method
7. Case-Insensitive Comparison for the Array.Sort Method
8. Iterating Through a Sparse Array
9. Using Functions to Iterate Through an Array
10. Reading and Writing Array Elements
11. Array with a numeric parameter and assign data to it
12. A string array
13. Array - properties and methods:length, join, reverse, push,pop,shift
14. Array - sort()
15. Array - concat and slice
16. Array - splice
17. Methods and Properties of the Array Object
18. Displaying the Contents of an Array
19. Using the Array.join() Method
20. Using JavaScript Arrays
21. Extending the Length of an Array
22. An Array within an Array
23. Using the Methods of the Array object
24. Array.sort() Possibilities
25. Array.reverse() Method
26.  Array Concatenation
27. A Simple Parallel Array Lookup
28. Adding a prototype Property
29. Two-Dimensional Array Work Around
30. Array definition and iteration
31. Reference an Array by index
32. URL Array
33. Array Utility functions
34. Dynamic array
w___w_w_._ja___v__a_2___s___.___c___o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.