473,320 Members | 2,092 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,320 software developers and data experts.

how to put a variable array inside the match() function?

Exequiel
288 256MB
Expand|Select|Wrap|Line Numbers
  1. function zipcode_detect(){
  2.  
  3.  
  4.     var albay_zipcode = Array("4509","4502","4501","4503","4515","4500","4507","4504","4510","4512","4514","4504","4516","4506","4517","4508","4511","4513");
  5.  
  6. var albay_town = Array("bacacay","camalig","daraga","guinobatan","jovellar","legazpi city","libon","ligao","malilipot","malinao","manito","oas","pio duran","polangui","rapu-rapu","sto. domingo","tabaco","tiwi");
  7.  
  8. var ddf = document.form_zip.addrz.value;
  9.  
  10.  
  11.     for(var count = 0; count<18; count++ ){
  12.         var input = ddf.match(albay_town[count]);    
  13.         if(input){
  14.             alert('match '+albay_zipcode[count]);
  15.  
  16.         }else{
  17.             alert('not');    
  18.  
  19.         }
  20.     }
  21. }//end of function
  22.  
i want to check if the value of my textfield has a word match in my array albay_town widthout using the for loop.
example input: camalig, albay;
the output must be: match 4502;
can you help me please. . . :)
Feb 14 '13 #1
2 1573
Rabbit
12,516 Expert Mod 8TB
You can use the indexOf method of the array class to look for the position matching a specified value.

However, you will get no results in your example case because you're looking for "camalig, albay" and there is no such value in your array. You only have "camalig" in your array.
Feb 14 '13 #2
Exequiel
288 256MB
Expand|Select|Wrap|Line Numbers
  1.  function zipcode_detect(){
  2.  
  3.  
  4. var albay_zipcode = Array("4509","4502","4501","4503","4515","4500","4507","4504","4510","4512","4514","4504","4516","4506","4517","4508","4511","4513");
  5.  
  6. var albay_town = Array("bacacay","camalig","daraga","guinobatan","jovellar","legazpi city","libon","ligao","malilipot","malinao","manito","oas","pio duran","polangui","rapu-rapu","sto. domingo","tabaco","tiwi");
  7.  
  8. var ddf = document.form_zip.addrz.value;
  9. var input = ddf.toLowerCase();    
  10.  
  11.     for(var count = 0; count<18; count++ ){
  12.      if(input.match(albay_town[count])){
  13.         alert('match '+albay_zipcode[count]);
  14.         break;
  15.     }     
  16.     }
  17. }//end of function
I got it already. . . i used this codes
Feb 15 '13 #3

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

Similar topics

1
by: Alex | last post by:
Is there any problem with sending function pointers through in a variable argument list? I have a function like the following: typedef (*ptr2FuncType1)( int ); typedef (*ptr2FuncType2)( double...
2
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
9
by: sathya | last post by:
I was going through an Boyer-Moore-Horspool pattern match, I saw a array inside a array, like the below, skip ] = patlen - i - 1; The array is decleared as int skip; unsigned char *pat;
10
by: tony | last post by:
i'm trying to itterate through an array that contains the names of the global arrays eg: $myarray = array("\$_GET", "\$_SERVER"); and so on The problem Im having is calling a function...
3
by: Chris | last post by:
I am clearly missing something simple here.... I have a function (fileTree) that recursively reads all the files in a directory passed to it, and returns an array of the files, I have included...
3
by: Ralph | last post by:
Hi Is this possible? One thing I can do is create the global array and add the new item to it from inside the function but that's not what I'm looking for. Thank you Ralph
4
by: Ray | last post by:
Hello, I think I've had JavaScript variable scope figured out, can you please see if I've got it correctly? * Variables can be local or global * When a variable is declared outside any...
4
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
5
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
4
Dheeraj Joshi
by: Dheeraj Joshi | last post by:
Hi, I was wondering is there any technique available, so we can access the global variable inside a function if we have a local variable inside the function with the same name as global variable. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.