473,387 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Array is undefined in line of code

In the second function , the array is coming up as undefined. Any Ideas ?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. var year = ["1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014","2014"];
  4.  
  5. var plateYear = ["97", "98", "99", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "131", "132", "141", "142" ];   
  6.  
  7. var counties = ["Cork", "Clare", "Cavan", "Carlow", "Dublin", "Donegal", "Galway", "Kildare", "Kilkenny", "Kerry", "Limerick", "Longford", "Louth", "Leitrim", "Laois", "Meath", "Monaghan", "Mayo", "Offaly", "Roscommon", "Sligo", "North Tipperary", "South Tipperary", "Waterford", "Westmeath", "Wexford", "Wicklow" ]; 
  8.  
  9. var plates = ["C", "CE", "CN", "CW", "D", "DL", "G", "KE", "KK", "KY", "L", "LD", "LH", "LM", "LS", "MH", "MN", "MO", "OY", "RN", "SO", "TN", "TS", "W", "WH", "WX", "WW" ];
  10.  
  11.  
  12. function formGet (form) 
  13. {
  14. event.preventDefault();
  15. console.log(form);
  16. var carYear = form.reg1.value;
  17. console.log("reg1" + carYear);
  18. var b = carYear.toString();
  19. var a = plateYear.indexOf(b);
  20. console.log("a" + a);
  21. var newYear = year [a];
  22. alert("Year Car was made :   "  + newYear);
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. event.preventDefault();
  30. console.log(form);
  31. var carCounties = form.reg2.value;
  32. console.log("reg2" + plates);
  33. var b = counties.toString();
  34. var a = plates.indexOf(b);
  35. console.log("a" + a);
  36. var newCounty = carCounties [a];
  37. alert ("County where car was registered :  " + newCounty);
  38. }
May 7 '14 #1
1 1244
Dormilich
8,658 Expert Mod 8TB
carCounties is a string, not an array.

besides that you should rather use objects to avoid data inconsistencies.

Expand|Select|Wrap|Line Numbers
  1. var counties = {
  2.   C : "Cork",
  3.   CE : "Clare",
  4.   etc.
  5. };
  6. var county = counties[plate];
and the year conversion is easy as well
Expand|Select|Wrap|Line Numbers
  1. var carYear = +form.reg1.value.substr(0,2) + 2000;
  2. if (carYear > 2014) {
  3.   carYear -= 100;
  4. }
May 7 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave Casserly | last post by:
<html> <head> <title>Testing JSP</title> <script type="text/javascript"> var numbers = new Array("one", "two", "three", "four", "five"); function test() { for(var i = 0; i < 5; i++) {
2
by: Fred Armitage | last post by:
I have a fairly complex application written using a vb code-behind dll. However, I'd like to write one particular aspx page utilising in-line code so that it can easily be modified as needed by the...
1
by: redhair | last post by:
In a asp.net page (.aspx) below, I'd like to know the in-line code ("<%Output()%> ) will be executed in which page process lifecycle? thanks. <Script Language="VB" Runat="Server"> Sub...
2
by: Eric Sabine | last post by:
Below is a sub I have which contains 4 lines of code. I would like to reduce it to 1. My problem is that it takes 3 lines to create the array to hold the sql parameter and since there's only one...
3
by: Boni | last post by:
Dear all, I have written a C++ com object: STDMETHOD(myfunc)(INT* array) Now I need to pass an array from c# to com. I generated a COM interop and it the signature of the function is ...
0
by: Jon Paal | last post by:
what would be the command line code to add an image as a resource to a dll ?
0
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
1
by: rahullko05 | last post by:
one line code to replace an image without page refresh
1
by: rahullko05 | last post by:
Can anybody help me? to write one line code to render html inside a div element. Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.