Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Having problems with running my html on anything but FireFox.

Posted on 2011-03-25
6
Medium Priority
?
351 Views
Last Modified: 2013-12-08
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
Comment
Question by:amd11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 35217276
wrap your functions in script tags and move them into the header.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35217284
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
 

Author Comment

by:amd11
ID: 35217642
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
Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

 
LVL 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 2000 total points
ID: 35217796
"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
 

Author Comment

by:amd11
ID: 35218748
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
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 35218874
"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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question