Jump to content

Browser lock up


xcandiottix

Recommended Posts

I'm not sure if JS or PHP is causing my browser to lock up when I access this page. I have a database of zipcodes ... approx. 70,000 of them. I have a php loop put them into a JS array. I then want JS to create a drop down with all the zip codes. On Chrome it completely doesn't work. On FF it will loop to about 64,000 and then give a warning that the script is taking too long. Reading up on google it seems that JS should be able to handle an array much bigger then mine... so what could be he problem?

 

<script language="javascript"> 

function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
<?php
//TESTING
$con = mysql_connect("","","");
mysql_select_db("", $con);
//END TESTING
$data = mysql_query("SELECT postalCode FROM geo_city WHERE postalCode !='' ORDER BY postalCode ASC") or die(mysql_error());
echo 'function addOption_list(selectbox){ 
var zip = new Array("VOID"';
while($info = mysql_fetch_array($data)){ 
echo ',"'.$info['postalCode'].'"';
}
echo ');';
?>
for (var i=0; i < zip.length;++i){

addOption(document.drop_list.zip_list, zip[i], zip[i]);
}
}
</script> 
</head> 

<body onLoad="addOption_list()";> 
<FORM name="drop_list" action="" method="POST" > 

<SELECT  NAME="zip_list">  
<Option value="" >Zip Code list</option> 
</SELECT> 
</form>

Link to comment
https://forums.phpfreaks.com/topic/209993-browser-lock-up/
Share on other sites

I decided to go a different route, utilizing some ajax to populate a drop down of suggestions after the user starts to type a zip code. Now I have a funny problem.

 

My set up looks like this:

Specify Zip Code [input box]

Suggestions:[drop down]

 

Now, if I enter 4 into Specify Zip Code my drop down is populated with every zip that starts with the number 4. The problem begins when I try my own zip code. My zip code is 46530. So, if I enter 46 .. 46530 is on the drop down. If I enter 465 .. 46530 is on the drop down. If I enter 4653 .. 46530 disappears!  :confused:

 

I think it must be that substr or strlen is ignoring the final zero of the zip code .. is there a fix for this?

 

// $q = user entry into 'specify zip code'
// $a[$i] = array created from db with all zip codes

//probable trouble code: 

if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/209993-browser-lock-up/#findComment-1096066
Share on other sites

To add a little more to the insanity..

 

entering 60110 results in:

 

6 - all zips starting with 6 including 60110

60 - all zips starting with 60 including 60110

601 - all zips starting with 601 including 60110

6011 - all zips starting with 6011 including 60110

 

yet mine, 46530, results:

 

4 - all zips starting with 4 including 46530

46 - all zips starting with 46 including 46530

465 - all zips starting with 465 including 46530

4653 - Lists zips 46532, 46534, 46536, 46539 but not 46530

 

strange.

 

 

(sorry for multiposting .. just updating as i test)

Link to comment
https://forums.phpfreaks.com/topic/209993-browser-lock-up/#findComment-1096069
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.