Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    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);

  • #5
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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';
    Last edited by pita0017; 11-03-2006 at 09:50 PM.
    "Beware of computer programmers that carry screwdrivers."
    -Leonard Brandwein.

  • #6
    New Coder
    Join Date
    Jul 2004
    Posts
    36
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I got it worked out, thanks you guys for the responses.
    "Beware of computer programmers that carry screwdrivers."
    -Leonard Brandwein.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •