...

View Full Version : Area Code Lookup



klturi421
08-27-2010, 12:26 AM
I am looking for a simple script or I hope it seems. I need the script to function like this:

[text box] insert telephone number here in format like this xxx-xxx-xxxx

but once the number is entered I would like for it to auto detect the area code and in a box or just as text to the right or left I would like for it to display the state that the area code corresponds with. I am using a set of predetermined area codes that I can enter myself once I am made aware of the script.

IF this is possible then I would greatly appreciate the help!

gizmo1650
08-27-2010, 01:31 AM
<script type="text/javascript">
region=[//2 dimensional array containing area codes and region pairs
["201","nj"],
["202","dc"],
]


function getRegion(code){
index=0;
while(true){
console.log(index);
if(region[index][0]==code){
return(region[index][1]);
}
index++;
if(index>=region.length){
return(undefined);
}
}
}

function getLocation(number){
out=document.getElementById('output');
var answer;
if(number.length<3){
return(void(0));
}
else{
var code=number.substring(0,3);
answer=getRegion(code)
if(answer==undefined){
out.innerText="unknown area code";
}
else{
out.innerText=answer;
}
}
}
</script>
...
<form>
<input type="text" id="number" onkeyup="getLocation(this.value)">
</form>
<div id="output">
</div>

you might want to use excel to help make the array

klturi421
08-27-2010, 03:37 AM
what about an auto format?

say for instance I plugin 2029878989 and want it to look like 202-987-8989

is that possible?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum