Personal Finance - Share Prices - Advertising - Bad Credit Mortgages - Loan

PDA

View Full Version : Need Help with Array and file setup, should be easy!!


id4382
Feb 4th 2008, 5:51 pm
Hello! I need help on how to create a var array for a list of about 500 cities. I am going to use this list in a geoIP variable to hide some text. I need the code to tell the if statement to look in the file 'cities.js', and if the city returned by the geoIP if statement equals a city in the list, then I need it to perform the function I have assigned.


Here is the code snippet, I need the list of cities to replace the 'stockton', without just typing them all out in the html file:

<script type="text/javascript" language="Javascript">


if (geoip_city() == "Stockton"){
HideText();
}

function HideText(){
var list = document.getElementsByTagName("font");
for (var i=0; i < list.length; i++) {
if (list[i].innerHTML.indexOf("Your Price:") > -1) {
list[i++].style.display="none";
if (list[i].innerHTML.indexOf("$") > -1) list[i].style.display="none";
}
}
}
//--></script>


Here is my array:
<script type="text/javascript">
<!--

var cityArray = NewArray();

cityArray[0] = "Alameda";
cityArray[1] = "Albany";
cityArray[2] = "Berkeley";
cityArray[3] = "Castro Valley";
cityArray[4] = "Dublin";
cityArray[5] = "Emeryville";
cityArray[6] = "Fremont";
cityArray[7] = "Hayward";
cityArray[8] = "Kensington";
cityArray[9] = "Livermore";
cityArray[10] = "Mount Eden";
cityArray[11] = "NAS Alameda";
cityArray[12] = "Newark";
cityArray[13] = "Oakland";
cityArray[14] = "Piedmont";
cityArray[15] = "Pleasanton";

-->
</script>

Anyone's help would be much appreciated!!!

locdev
Feb 5th 2008, 5:36 am
try to check it in loop:

for (var i=0; i < cityArray.length; i++) {
if (geoip_city() == cityArray[i]){
HideText();
}
}

id4382
Feb 5th 2008, 9:48 am
Well, after inputing the code, the if and function statements did not work. I have the array in a seperate file on my server. I even pasted the entire array code into the .htm file, and it still did not respond.

Here is the code snippet with external file:

<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script><script language="JavaScript" scr="http://www.industriallive.com/v/vspfiles/files/cities.js"></script><script type="text/javascript" language="Javascript">

for (var i=0; i < cityArray.length; i++) {
if (geoip_city() == cityArray[i]){
HideText();
}
}

function HideText(){
var list = document.getElementsByTagName("font");
for (var i=0; i < list.length; i++) {
if (list[i].innerHTML.indexOf("Your Price:") > -1) {
list[i++].style.display="none";
if (list[i].innerHTML.indexOf("$") > -1) list[i].style.display="none";
}
}
}
//--></script>


Not sure if there is still something wrong. Suggestions?

locdev
Feb 5th 2008, 2:05 pm
can you create a test page so we can see the error ?

id4382
Feb 5th 2008, 3:21 pm
Actually, I found out what was wrong, I had an extra "}" and it was throwing the code out, and excluding the function code. Thanks for your help!!