View Full Version : Javascript causing IE to crash

11-02-2006, 10:10 PM
I have the following code, really short, causing IE to crash, this works just fine in Firefox though. I call the function from a textbox onChange event.

function minutes2money()
var x = 0;

while(document.addmoneycc.countries.value != countryarr[x]){

var result1 = document.addmoneycc.minutes.value * ratearr[x];
document.addmoneycc["amount"].value = result1.toFixed(2);

Anyone know why this causes IE to crash? I'm having a hell of a time trying to figure out why. :confused:

Thanks in advance for any responses.

11-02-2006, 10:37 PM
It's probably because the statement:

document.addmoneycc.countries.value != countryarr[x]

never becomes false.

make sure that the form "addmoney" has both "id" and "name" attributes set to "addmoney" and that the "countries" element has both "id" and "name" attributes set to "countries" and that the value of the "countries" element is contained in the "countryarr" array.

11-03-2006, 12:03 AM
I'm sorry, let me explain some more.

I made both java arrays from the same MySQL database using this code:

print "<script type=\"text/javascript\">\n";
print "var countryarr = new Array();\n";
$i = 0;
$result = mysql_query("select country from rates");
while ( $row = mysql_fetch_assoc($result))
print "countryarr[$i] = \"$row[country]\";\n";
print "var ratearr = new Array();\n";
$i = 0;
$result = mysql_query("select rate from rates");
while ( $row = mysql_fetch_assoc($result))
print "ratearr[$i] = $row[rate];\n";
echo '</script>';

The countries element is filled from the same database.

At first I thought the same thing, that the loop never ended. However it works correctly in Firefox.

It stops at whatever value is selected in the countries element. It then uses the same index in the rates array.

Basically what I'm saying is I think the condition does become false, because it works flawlessly in Firefox. Now I just need to figure out what's making it crash in IE.

Thanks for your help Vortex.

Arty Effem
11-03-2006, 03:44 AM
Its not really good practice to take for granted a match between two sources of data, even if you do maintain them both.
To eliminate the doubt I would try try something like this:

while(document.addmoneycc.countries.value != countryarr[x] && x < countryarr.length)

alert("Match found: " + x!=countryarr.length);

11-03-2006, 10:06 PM
Alright so I did that and you guys are right, the condition never does become false.

Anyone know why in Firefox it does stop at the right place, and IE it doesn't work?

Damn IE....:mad:

Thanks for the helps. :thumbsup:

Here I thought this might help, this is a sample of the array on the actual page.

var countryarr = new Array();
countryarr[1] = 'ALBANIA FIXED';
countryarr[2] = 'ALBANIA MOBILE';
countryarr[3] = 'ALGERIA FIXED';
countryarr[4] = 'ALGERIA MOBILE';

11-03-2006, 11:42 PM
I got it worked out, thanks you guys for the responses.:)