Cant figure this Javascript out!!!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Cant figure this Javascript out!!!

  1. #1
    Join Date
    Feb 2006
    Posts
    4

    Cant figure this Javascript out!!!

    ok once again im confused, im tryin to make 2 arrays one with names and one with numbers, then as a number is entered it searches the parallel name array and displays the corresponding name. If the numbers not valid an error message needs to be alerted. Someone plzz help me. I dont know what im doing wrong.

    <script>
    var employeenumber=new Array('10001','20002','30003','40004','50005')
    var employeename=new Array('Jared','Mike','Tyrone','Quan Chi','Abraham')
    var inn
    var index
    var index2

    for(index=0;index<5;++index)
    {
    inn=prompt("Please enter an employee number")
    for(index2=0;index2<5;++index2)
    {
    if(inn==employeenumber[index2])
    index2=index2+5;
    else
    if(index2==4)
    {
    alert("wrong number.. resubmit");
    inn=prompt("Please enter an employee number");
    index2=-1;
    }
    }
    employeename[index]=inn;
    document.writeln("Number found, employee name is:" +employeename[index]);

    }
    </script>

    i dont know whats wrong..

  2. #2
    Join Date
    Mar 2006
    Location
    NYC
    Posts
    7
    you're code is really ugly!!!

    Try this:

    Code:
    <script>
    var employeenumber=new Array('10001','20002','30003','40004','50005')
    var employeename=new Array('Jared','Mike','Tyrone','Quan Chi','Abraham')
    var inn
    var index
    var index2
    
    var i = 0;
    inn=prompt("Please enter an employee number");
    
    var found = false;
    
    while (!found && i<5) {
    	if(inn==employeenumber[i]) found = true;
    	i++;
    }
    if (found) {
    	alert('found it:'+employeename[i]);
    	} 
    	else {
    	alert('not found:'+inn);
    	}
    
    
    </script>

Similar Threads

  1. Replies: 5
    Last Post: 05-06-2006, 10:22 PM
  2. problems with javascript
    By Michael in forum ASP.NET
    Replies: 10
    Last Post: 11-08-2005, 12:19 PM
  3. Help with Javascript in forms
    By Keith Sarver in forum Web
    Replies: 0
    Last Post: 12-14-2002, 02:18 PM
  4. Agents and JavaScript how??
    By Hakan Eren in forum Enterprise
    Replies: 0
    Last Post: 08-31-2001, 05:16 AM
  5. Sample Sites.
    By Murray Foxcroft in forum Web
    Replies: 5
    Last Post: 11-02-2000, 02:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center