Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

Having problems with running my html on anything but FireFox.

I am trying to write a html/javascript programme for my lecture, but am having problems. My code will only run in FireFox3.6. I tried running it in IE8 and IE9 and Safari but to no avail. I do not what is wrong with it. IE8 says it was "object expected" on line 95:
<td><input name="submit" id="submit" type="button" value="Calculate Grade" onclick="addResults()" /> </td>
but I cannot see the problem.

Also I am trying to display an image relating to the average grade. So if the avg grade is 40 or above, an PASS image shows. If it is below 60, an FAIL image is displayed. But I am stumped on how to create an function and an if statement that passes the avg.value to the if statement.

I have attached the html and the separate .js file

Appreciate any help given.
<?xml verson="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title> Results Page</title>
<script type = "text/javascript" src="Results.js">
</script>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>

<body>
<a href="LoginPage.html" alt="login page">Login</a>
<br/>
<br/>

<center><img src="pic1.jpeg" alt="pic1" height="100" width="100" /></center>

<h3>Student Details</h3>

<form action="">
<p>
<label>
<input type="text" id="custName"/> Name(First Name, Last Name, Middle Initial)
</label>
</p>
<p>
<label>
<input type="text" id="studentID"/> Student ID
</label>
</p>
<input type="button" value="Submit" id="Submit"
</form>

<br/>

<p> PLEASE ENTER IN RESULTS FOR SEMESTER 1. MARKS WILL BE TOTALED AND AN AVERAGE GRADE WILL BE ASSIGNED.</p>

<center>
<form name="myform" id="myform" width="60%">
<table width="500" border="1" cellspacing="1" cellpadding="1">

<tr>
<td><h3>MODULES</H3></td>
<td><h3>MARKS</h3></td>
<td><H3>GRADE</H3></td>
<td><H3>REPEAT</H3></td>
</tr>

<tr>
<td>Programming</td>
<td><input name="result1" id="result1" type="text" size="5"/></td>
<td><input name="grade1" id="grade1" type="text" size="5" /></td>
<td><input name="repeat1" id="repeat1" type="text" size="10" /></td>
</tr>

<tr>
<td>Web Development</td>
<td><input name="result2" id="result2" type="text" size="5"/></td>
<td><input name="grade2" id="grade2" type="text" size="5" /></td>
<td><input name="repeat2" id="repeat2" type="text" size="10" /></td>
</tr>

<tr>
<td>Networking</td>
<td><input name="result3" id="result3" type="text" size="5"/></td>
<td><input name="grade3" id="grade3" type="text" size="5" /></td>
<td><input name="repeat3" id="repeat3" type="text" size="10" /></td>
</tr>

<tr>
<td>WAN</td>
<td><input name="result4" id="result4" type="text" size="5"/></td>
<td><input name="grade4" id="grade4" type="text" size="5" /></td>
<td><input name="repeat4" id="repeat4" type="text" size="10" /></td>
</tr>

<tr>
<td>APS</td>
<td><input name="result5" id="result5" type="text" size="5"/></td>
<td><input name="grade5" id="grade5" type="text" size="5" /></td>	
<td><input name="repeat5" id="repeat5" type="text" size="10" /></td>
</tr>

<tr>
<td>Probabilty</td>
<td><input name="result6" id="result6" type="text" size="5"/></td>
<td><input name="grade6" id="grade6" type="text" size="5" /></td>
<td><input name="repeat6" id="repeat6" type="text" size="10" /></td>
</tr>

<tr>
<td><input name="submit" id="submit" type="button" value="Calculate Grade" onclick="addResults()" /> </td>
</tr>

<tr>
<td>Average Grade</td>
<td><input name="avg" id="avg" type="text" size="5"/></td>
</tr>

<tr>
<td><input type = "Reset" id="reset"/></td>
</tr>

</center>
</form>
 <script type = "text/javascript"  >
 document.getElementById("custName").onchange = chkName;
 </script>
</body>
</html>


function chkName() {
  var myName = document.getElementById("custName");

  var pos = myName.value.search(
            /^[A-Z][a-z]+, ?[A-Z][a-z]+, ?[A-Z]\.?$/);

  if (pos != 0) {
    alert("The name you entered (" + myName.value + 
          ") is not in the correct form. \n" +
          "The correct form is: " +
          "first-name, last-name, middle-initial \n" +
          "Please go back and fix your name");
    myFocus(myName);
    myName.select();
    return false;
  } else
    return true;
}


	

function addResults()
{   
	var RF = document.myform;
	   
	     if ((RF.result1.value != "") && (RF.result2.value != "") && (RF.result3.value != "") && (RF.result4.value != "") && (RF.result5.value != "") && (RF.result6.value != ""))     
	   {
	   RF.avg.value = ((parseInt(RF.result1.value) + parseInt(RF.result2.value) + parseInt(RF.result3.value) + parseInt(RF.result4.value) + parseInt(RF.result5.value) + parseInt(RF.result6.value)) / (6));
	   }   
      

for (i=1;i<=6;i++)
{
	   
	   var myfield = eval("RF.result"+i);
	   var updateField = eval("RF.grade"+i);
	   var repeatField = eval("RF.repeat"+i);
	   
	   if (myfield.value < 40)
	   {
	   repeatField.value = 'Repeat Exam';
	   }
		else
		{
		repeatField.value = '-';
		}

			   if (myfield.value <= 100 && myfield.value >= 85)
	   {
	   	   updateField.value = 'A';
	   }
	   else if (myfield.value <= 84 && myfield.value >= 70)
	   {
	   	   updateField.value = 'B';
	   }
	   else if (myfield.value <= 69 && myfield.value >= 55)
	   {
	   	   updateField.value = 'C';
	   }
	   else if (myfield.value <= 54 && myfield.value >= 40)
	   {
	   	   updateField.value = 'D';
	   }
	   else if (myfield.value <= 39)
	   {
	   	   updateField.value = 'FAILED';
	   }
	 
	  

}
}

Open in new window

0
amd11
Asked:
amd11
  • 3
  • 2
2 Solutions
 
Kyle AbrahamsSenior .Net DeveloperCommented:
wrap your functions in script tags and move them into the header.
0
 
Dave BaldwinFixer of ProblemsCommented:
What you have posted won't run in Firefox either.  You have an undefined variable ('checkbox') in line 110 which should probably be 'checkbox()'.  And the javascript at the bottom is not inside <script> tags.  And the <input> on line 34 does not have a closing tag.

To check it further, we will need the code for "Results.js".  The "style.css" file would be nice also.
0
 
amd11Author Commented:
Sorry I am used to writing my  javascript on a separate document. I have attached it know. I also attached the html as a separate file too, so ye have everything. ResultsPage.html Results.js style.css
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Dave BaldwinFixer of ProblemsCommented:
"myFocus(myName);" is undefined in Firefox on line 48 of "Results.js".  IE8 doesn't like the opening '//' in "Results.js" either.  I can't tell how you mean to be grouping your code in that file.

IE8 also doesn't like something in  document.getElementById("custName").onchange = chkName(); .  Either, it's not finding 'custName' or 'chkName()'.

And the last line in your CSS file is missing a '}'.
0
 
amd11Author Commented:
Thanks after changing a few of the items you suggested, it's seems to be working in IE again. Thanks very much.

I just have one more question, I am trying to display an image as a result of an if statement such as:

if (avg.value < 40)
{
document.write("img src= "fail.jpg" alt="fail" height ="30" width="30" />
}
else
{
document.write("img src= "pass.jpg" alt="passl" height ="30" width="30" />
}

I have tried to place the code in the middle of the function addResults() but then the addResults() doesn't work. It is wrecking my head because I cannot find another way to do it.

I don't know is it because you cannot do it like this or something else. The image is used to display whether the student has passed the semester based on the average grade.

Thanks     fail image pass image
0
 
Dave BaldwinFixer of ProblemsCommented:
"document.write" has to be used inline where the image or text should appear.  To assign the image from the script in the <head>, you need to use something like below.  I had to change 'avg.value' to 'avg' because I don't have 'avg' on the page.  You should be able to use 'avg.value' in your page.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>JS image place</title>
<script type="text/javascript">
<!--
function setit() {
avg = 139;
if (avg < 40)
{
document.getElementById("Result").innerHTML = "<img src='fail.jpg' alt='fail' height='30' width='30' />";
}
else
{
document.getElementById("Result").innerHTML = "<img src='pass.jpg' alt='passl' height='30' width='30' />";
}
}
// -->
</script>
</head>
<body onload="setit();">
<h1>JS image place</h1>
<div id="Result">&nbsp;</div>

<img src='fail.jpg' alt='fail' height='30' width='30' />&nbsp;<img src='pass.jpg' alt='passl' height='30' width='30' />
</body>
</html>

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now