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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Alert() not working in Firefox or Safari

    I have created a simple grade calculator, and it works very well in Internet Explorer, however, when I access this page from Firefox or Safari, somehow alert() isn't working.

    This is the webpage address.
    http://homepage.mac.com/yamadatakayo...alculator.html

    It is supposed to take inputs from the text field, and then when calculated, it pops up an alert window, indicating the final official grade. But in firefox, this never works.

    I will appreciate any help on this matter.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
    <title> Grade Calculator </title>
    
    
    <SCRIPT type="text/javascript" LANGUAGE="JavaScript">
    <!--
    
    function reset() {
      document.gradeCalc.HW1.value = 0;
      document.gradeCalc.HW2.value = 0;
      document.gradeCalc.HW3.value = 0;
      document.gradeCalc.HW4.value = 0;
      document.gradeCalc.final.value = 0;
    }
    
    function calcgrade() {
    var grade = new Array(5);
    grade[0] = parseFloat(document.gradeCalc.HW1.value);
    grade[1] = parseFloat(document.gradeCalc.HW2.value);
    grade[2] = parseFloat(document.gradeCalc.HW3.value);
    grade[3] = parseFloat(document.gradeCalc.HW4.value);
    grade[4] = parseFloat(document.gradeCalc.final.value);
    var check = 2; //integer value to validate if float was entered correctly
    
    for(var i=0; i<5; i++)
    {
    	if(isNaN(grade[i]))
    	{
    		check = 0; //set false to float validation
    	}
    }
    
    if(check == 0)
    {
    	alert("One or more numeric values have been entered incorrectly. Try again.");
    	reset();
    }
    else
    {
    	for(var j = 0; j < 5; j++)
    	{
    		if(grade[j] > 100 || grade[j] < 0)
    		{
    		 check = 1;
    		}
    	}
    	if(check == 1)
    	{
    		alert("One or more numeric values have either less than 0 or more than 100. Try again.");
    		reset();
    	}
    	else
    	{
    	var max1, max2, max3;
    	var min1, min2;
    	max1 = Math.max(grade[0],grade[1]);
    	max2 = Math.max(grade[2],grade[3]);
    	min1 = Math.min(grade[0],grade[1]);
    	min2 = Math.min(grade[2],grade[3]);
    	max3 = Math.max(min1, min2);
    
    	var sumHomework = max1 + max2 + max3;
    	var finalSumGrade = 0.2 * sumHomework + 0.4 * grade[4];
    	var finalOfficialGrade = Math.floor(10 * Math.max(finalSumGrade, grade[4])) / 10;
    	alert("Final Grade is " + finalOfficialGrade + ". Notice that the lowest assignment grade has been dropped.");
    	}
    }
    }
    //-->
    </script>
    </head>
    
    <body>
    <CENTER>
    <FORM Name="gradeCalc">
    
    <TABLE BORDER=2 BGCOLOR=#C0C0C0 CELLPADDING="2" CELLSPACING="2">
    <TH></TH>
    <TH>Grade</TH>
    
    <TR>
    <TD>Assignment 1</TD>
    <TD><INPUT TYPE=TEXT SIZE=5 NAME="HW1" ALIGN=TOP
    MAXLENGTH=5 VALUE=0></TD>
    </TR>
    
    <TR>
    <TD>Assignment 2</TD>
    <TD><INPUT TYPE=TEXT SIZE=5 NAME="HW2" ALIGN=TOP
    MAXLENGTH=5 VALUE=0></TD>
    </TR>
    
    <TR>
    <TD>Assignment 3</TD>
    <TD><INPUT TYPE=TEXT SIZE=5 NAME="HW3" ALIGN=TOP
    MAXLENGTH=5 VALUE=0></TD>
    </TR>
    
    <TR>
    <TD>Assignment 4</TD>
    <TD><INPUT TYPE=TEXT SIZE=5 NAME="HW4" ALIGN=TOP
    MAXLENGTH=5 VALUE=0></TD>
    </TR>
    
    <TR>
    <TD>Final Exam</TD>
    <TD><INPUT TYPE=TEXT SIZE=5 NAME="final" ALIGN=TOP
    MAXLENGTH=5 VALUE=0></TD>
    </TR>
    
    <TR ALIGN=CENTER>
    <TD COLSPAN=3><INPUT TYPE="BUTTON" VALUE="Calculate"
    NAME="calcButton" OnClick="calcgrade()"></TD>
    </TR>
    
    <TR ALIGN=CENTER>
    <TD COLSPAN=3><INPUT TYPE="BUTTON" VALUE="Reset"
    NAME="resetButton" OnClick="reset()"></TD>
    </TR>
    
    </TABLE>
    </FORM>
    </CENTER>
    
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It works in FF1.5 but not in FF1.0.

    The error message FF1.0 gives makes me think you should try retyping this line:
    Code:
    document.gradeCalc.final.value = 0;
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for pointing out that it actually works in Firefox 1.5.

    I updated my firefox and yes it does work.

    I still find this javascript based webpage broken in Safari, but it is ok.

    Thanks for taking time for looking at this massive code!!!

  • #4
    Regular Coder
    Join Date
    Dec 2002
    Location
    a bit west of pittsburgh
    Posts
    236
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I think the correct DOM usage would be:
    document.forms.gradeCalc.name.value;

    I may be wrong, though.

  • #5
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    He's using the short form.

    You could also use the full DOM0 form which is:
    Code:
    document.forms.gradeCalc.elements.name.value
    OR with mixed dot and array syntax
    Code:
    document.forms['gradeCalc'].elements['name'].value
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.


  •  

    Posting Permissions

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