Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-02-2006, 09:10 PM   PM User | #1
pita0017
New Coder

 
Join Date: Jul 2004
Posts: 36
Thanks: 2
Thanked 0 Times in 0 Posts
pita0017 is an unknown quantity at this point
Javascript causing IE to crash

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.

Code:
function minutes2money()
{
var x = 0;

while(document.addmoneycc.countries.value != countryarr[x]){
        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.

Thanks in advance for any responses.
pita0017 is offline   Reply With Quote
Old 11-02-2006, 09:37 PM   PM User | #2
VortexCortex
Regular Coder

 
Join Date: May 2005
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
VortexCortex is an unknown quantity at this point
It's probably because the statement:
Code:
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.
VortexCortex is offline   Reply With Quote
Old 11-02-2006, 11:03 PM   PM User | #3
pita0017
New Coder

 
Join Date: Jul 2004
Posts: 36
Thanks: 2
Thanked 0 Times in 0 Posts
pita0017 is an unknown quantity at this point
I'm sorry, let me explain some more.

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

PHP 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";
    
$i++;
}
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";
    
$i++;
}
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.
pita0017 is offline   Reply With Quote
Old 11-03-2006, 02:44 AM   PM User | #4
Arty Effem
Banned

 
Join Date: May 2006
Location: England
Posts: 664
Thanks: 0
Thanked 84 Times in 84 Posts
Arty Effem can only hope to improve
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:
Code:
while(document.addmoneycc.countries.value != countryarr[x] && x < countryarr.length)
 x++;

alert("Match found: " + x!=countryarr.length);
Arty Effem is offline   Reply With Quote
Old 11-03-2006, 09:06 PM   PM User | #5
pita0017
New Coder

 
Join Date: Jul 2004
Posts: 36
Thanks: 2
Thanked 0 Times in 0 Posts
pita0017 is an unknown quantity at this point
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....

Thanks for the helps.

Here I thought this might help, this is a sample of the array on the actual page.
Code:
var countryarr = new Array();
countryarr[0] = 'AFGHANISTAN FIXED AND MOBILE';
countryarr[1] = 'ALBANIA FIXED';
countryarr[2] = 'ALBANIA MOBILE';
countryarr[3] = 'ALGERIA FIXED';
countryarr[4] = 'ALGERIA MOBILE';
__________________
"Beware of computer programmers that carry screwdrivers."
-Leonard Brandwein.

Last edited by pita0017; 11-03-2006 at 09:50 PM..
pita0017 is offline   Reply With Quote
Old 11-03-2006, 10:42 PM   PM User | #6
pita0017
New Coder

 
Join Date: Jul 2004
Posts: 36
Thanks: 2
Thanked 0 Times in 0 Posts
pita0017 is an unknown quantity at this point
I got it worked out, thanks you guys for the responses.
__________________
"Beware of computer programmers that carry screwdrivers."
-Leonard Brandwein.
pita0017 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:51 AM.


Advertisement
Log in to turn off these ads.