Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to make this array work with FireFox?

    How would I go about having this work for Firefox. Is there away to have JQuery work with it?

    Code:
    <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>

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    Code:
    <script type="text/javascript">
    region=[//2 dimensional array containing area codes and region pairs
    ["201","nj"],
    ["202","dc"],
    ]
    
    
    function getRegion(code){
    	index=0;
    var text=null;
    
    	while(region[index]){
    		  //console.log(index) 
    		if(region[index][0]==code){
    			 text=(region[index][1]);
    		}
    		index++;
    		 
    	}
    return text
    }
    
    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.innerHTML="unknown area code";
    		}
    		else{
    			out.innerHTML=answer;
    		}
    	}
    }
     
    </script>
    ...
    <form>
    	<input type="text" id="number" onchange="getLocation(this.value)">
    </form>
    <div id="output">
    </div>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •