Error only in IE

Discussion in 'JavaScript' started by danny-k, Sep 18, 2007.

  1. #1
    I have this JS code to calculate some points, under FireFox forks great but with IE I get an error:
    The same code works fine (firefox + IE) if he's on a separate page see http://ethereals.bynetics.net/arena.html

    Any suggestions?

    PS: IE v7.0.5730.11
    FireFox v2.0.06

    <SCRIPT LANGUAGE="JavaScript">
    var ap
    var t
    var r
    function testButton (form){
        for (Count = 0; Count < 3; Count++) {
            if (form.rad[Count].checked)
                break;
        }
    	t = form.rad[Count].value
    	r = form.rating.value
    if (r>1500) { ap = 1426.79 /(1+918.836*Math.pow(2.71828,(-0.00386405*r)));}
    else { ap = 0.38*r-194;}
    if (t==2) {ap= Math.floor(0.7*ap);}
    if (t==3) {ap= Math.floor(0.8*ap);}
    if (t==5) {ap= Math.floor(ap);}
    if (ap<=0) {ap=0;}
    alert("Your " + t + "v" + t + " team gets for " + r + " rating\n" + ap + " Arena Points");
    }
    </SCRIPT>
    </BODY>
    <FORM NAME="testform">
    <INPUT type="text" NAME="rating" size="4" value="1500"/><BR>
    <table width="40" border="0">
    <tr>
    <td><INPUT TYPE="radio" NAME="rad" Value="2" onClick=0 checked>
    2v2</td>
    <td><INPUT TYPE="radio" NAME="rad" Value="3" onClick=0>
    3v3</td>
    <td><INPUT TYPE="radio" NAME="rad" Value="5" onClick=0>
    5v5 </td>
    </tr>
    </table>
    <BR>
    <INPUT TYPE="button" NAME="button" Value="Calculate" 
        onClick="testButton(this.form)"> <BR>
    </FORM>
    PHP:
     
    danny-k, Sep 18, 2007 IP
  2. danny-k

    danny-k Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I used Microsoft Script Editor, and the Error is on this line:
        for (Count = 0; Count < 3; Count++) {
    HERE-->       if (form.rad[Count].checked)
                break;
    }
    PHP:
     
    danny-k, Sep 19, 2007 IP
  3. danny-k

    danny-k Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no ideas, something else wrong in the page?
    Help pls... page looks unfinished with: "Works with Firefox only"...
     
    danny-k, Sep 21, 2007 IP
  4. KatieK

    KatieK Active Member

    Messages:
    116
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #4
    It is curious - I've noticed that sometimes IE has a stricter JavaScript engine than Firefox.

    Can you post a link to the page where the error is occuring?
     
    KatieK, Sep 21, 2007 IP
  5. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try
    if (document.getElementsByName('rad')[Count].checked)
     
    MMJ, Sep 22, 2007 IP
  6. danny-k

    danny-k Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hi, just come back from a vacation... so

    I tried the replacement and it was ok, to 1 point :| when i tried to replace the next form.
    It is correct to replace:
        for (Count = 0; Count < 3; Count++) {
            if (form.rad[Count].checked)
                break;
        }
        t = form.rad[Count].value
        r = form.rating.value
    PHP:
    with
        for (Count = 0; Count < 3; Count++) {
            if (document.getElementsByName('rad')[Count].checked)
                break;
        }
        t = document.getElementsByName('rad')[Count].value
        r = document.getElementsByName('rating').value
    PHP:
    the script works but i get:
    "Your 2v2 team gets for undefined rating NaN Arena Points"

    seams that the "t" and "r" aren't correct
     
    danny-k, Oct 3, 2007 IP
  7. danny-k

    danny-k Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    did I defined the variables corect in JS?
    var ap
    var t
    var r
    Code (markup):
     
    danny-k, Oct 11, 2007 IP
  8. danny-k

    danny-k Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    /up

    pls can someone look at this again, my Firefox was blocked recently :( and the script dosn't run uder IE :(
     
    danny-k, Oct 25, 2007 IP
  9. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #9
    this is really funny, hehe.

    It doesn't work in ie because you don't close the <center> tag.

    i.e.:

    <center
    <form...

    which doesn't put it in the dom tree for ie.
    I closed the <center> tag and it worked.

    an excellent example of why you should validate with the W3 validator.
     
    MMJ, Oct 28, 2007 IP
  10. danny-k

    danny-k Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Oh my god :eek:
    I still cant belive that this was the reason ...

    Still mozilla seams to be better - it worked without the tag closed.

    Ty all.
     
    danny-k, Oct 28, 2007 IP