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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.