Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old November 27th, 2008, 02:38 PM   #1
New Member
 

Join Date: Nov 2008
Location: Newcastle
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 DarkDragons is on a distinguished road
JavaScript Array Help

Can somebody have a look at this bit of code.
HTML Code:
<html>
<script>

        var studentNum = new Array(2)
        var students = new Array(2)
        var eMail = new Array(2)
        
        for(var i = 0; i < studentNum.length; i++)
        {
            studentNum[i] = eval(prompt("Enter Student Number: " + i));
            students[i]= prompt("Enter Student Name: " + i)
            eMail[i] = prompt("Enter Students E-Mail: " + i)
        }

        var searchingFor = eval(prompt("Enter Students Number "));
        var j = 0;
        for(j in studentNum)
        {
            if (studentNum[j] == searchingFor)
            {
                alert("Student Number: " + searchingFor + "\nName: " +
                students + "\nE-Mail: " + eMail);
                break;
            }
        }    
</script>
</html>
Can anyone spot the problem and help with a solution please.

What I've been trying to do is search for a single value in an array of strings, yet when it outputs as seen below more than one value is outputted in the Name and E-Mail.

Last edited by Aso; November 28th, 2008 at 05:52 AM.. Reason: PLEASE wrap your code in [html]
DarkDragons is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old November 28th, 2008, 06:03 AM   #2
Aso
Most Reputable Member
 

Join Date: Oct 2007
Location: UK
Posts: 1,633
Blog Entries: 2
Thanks: 22
Thanked 84 Times in 79 Posts
Rep Altering Power: 0 Aso is on a distinguished road
Re: JavaScript Array Help

This line;
HTML Code:
students + "\nE-Mail: " + eMail);
Should be this;
HTML Code:
students[j] + "\nE-Mail: " + eMail[j]);
Aso is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help or ideas for improving a javascript gallery / array please JethroTull JavaScript 2 July 23rd, 2008 05:38 PM
array of class janper Flash and ActionScript 4 April 9th, 2007 09:54 AM
Top 4 array to text box buzcajun Flash and ActionScript 10 September 14th, 2006 03:13 PM
Sorting a new array from an existing array Ozeona Flash and ActionScript 2 September 20th, 2005 04:43 AM
array unable to check another array so as to be displayed Ozeona Flash and ActionScript 1 August 5th, 2005 06:26 AM


Search Engine Optimization by vBSEO 3.2.0 RC8