JavaScript widget not working -- help!

T

tashfeenmahmud

Hello, I wrote a small JavaScript grade calculator for my students and
put it on my blog. I've added it as a widget that appears only for a
particular page.

Problem:
it's not working (but the local file on my computer is running
perfectly). Could anybody please take a look at it and tell me how to
fix this thing?

Here's the link:
http://techqi.blogspot.com/2008/02/beta.html

Sincerely,
T.
 
M

mrcakey

Hello, I wrote a small JavaScript grade calculator for my students and
put it on my blog. I've added it as a widget that appears only for a
particular page.

Problem:
it's not working (but the local file on my computer is running
perfectly). Could anybody please take a look at it and tell me how to
fix this thing?

Here's the link:
http://techqi.blogspot.com/2008/02/beta.html

Have your tried running it through here?

http://www.jslint.com/

+mrcakey

P.S. - Web Developer plugin in FF gives the following (in addition to
several dozen warnings):

Error: missing ; before statement
Source File: http://techqi.blogspot.com/2008/02/beta.html
Line: 559, Column: 5
Source Code:
<br/>function gradeCalc() { <br/> var sum = 0;<br/> var whole = 0;<br/> var
xperc = 0;<br/> var xgrade = 0;<br/> <br/> sel1 =
document.gradeform.sel1.value;<br/> if (sel1 == "yes") {<br/> inclass1 =
document.gradeform.inclass1.value;<br/> onSubmit(incl
 
J

Jonathan N. Little

mrcakey said:
Have your tried running it through here?

http://www.jslint.com/

+mrcakey

P.S. - Web Developer plugin in FF gives the following (in addition to
several dozen warnings):

Error: missing ; before statement
Source File: http://techqi.blogspot.com/2008/02/beta.html
Line: 559, Column: 5
Source Code:
<br/>function gradeCalc() { <br/> var sum = 0;<br/> var whole = 0;<br/> var
xperc = 0;<br/> var xgrade = 0;<br/> <br/> sel1 =
document.gradeform.sel1.value;<br/> if (sel1 == "yes") {<br/> inclass1 =
document.gradeform.inclass1.value;<br/> onSubmit(incl

That will certainly foul things up, HTML within your JavaScript.

Note: Within an HTML document when using inline scripting what goes
between the <script type"text/javascript"> and </script> tags should
obey JavaScript syntax rules not HTML.
 
C

cwdjrxyz

Hello, I wrote a small JavaScript grade calculator for my students and
put it on my blog. I've added it as a widget that appears only for a
particular page.

Problem:
it's not working (but the local file on my computer is running
perfectly). Could anybody please take a look at it and tell me how to
fix this thing?

Here's the link:http://techqi.blogspot.com/2008/02/beta.html

page url into the official W3C validator at http://validator.w3.org/
, and select more options and select show source and verbose output,
then you will find the page is over 1000 lines long and has well over
500 validation errors. If the page does not work after you fix all of
these errors, then it is time to see if any script corrections are
needed. If you find the page still has problems and you want someone
to check it, you then need to write a simple example page that
includes only the part with the problem and not all of the extra stuff
such as as ads etc. Or you might carefully set off the page with
comments so that the problem scripts are easy to find.
 
H

Harlan Messinger

Hello, I wrote a small JavaScript grade calculator for my students and
put it on my blog. I've added it as a widget that appears only for a
particular page.

Problem:
it's not working (but the local file on my computer is running
perfectly). Could anybody please take a look at it and tell me how to
fix this thing?

Here's the link:
http://techqi.blogspot.com/2008/02/beta.html

Sincerely,
T.
Firebug reports:

missing ; before statement
[Break on this error] <br/>function gradeCalc() { <br/> var sum =
0;<br/> var whole = 0;<br/> var xper...
beta.html (line 559)

deconcept.util.getRequestParameter is not a function
[Break on this error] this.skipDetect =
deconcept.util.getRequestParameter(this.DETECT_KEY);
ads.js (line 21)

Do you know that there are <br/> tags between your script tags? They
don't belong there.
 
T

tashfeenmahmud

Thanks to everyone who replied to this post. I've updated the page on
my blog to reflect my current status regarding this issue (http://
techqi.blogspot.com/2008/02/beta.html).

Anyway, I'm lost and I'm no expert. Never used Firebug etc. I'm
pasting the code below, works fine on my system:
--------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Grade Calculator</title>
<style type="text/css">
<!--
..style1 {font-size: x-small}
..style2 {
color: #FF0000;
font-weight: bold;
}
-->
</style>
</head>
<body>
<form name="gradeform">
<table width="424">
<tr>
<td width="279"><strong>Enter your scores below: </strong></td>
<td width="60">&nbsp;</td>
<td width="69" valign="bottom"><div align="center"><span
class="style1">include?</span></div></td>
</tr>
<tr>
<td>1st in-class essay on Simple Recipes (15%):</td>
<td><input type="text" name="inclass1" size="10" maxlength="10" >
</td>
<td><div align="right">
<select name="sel1" id="sel1">
<option selected>no</option>
<option>yes</option>
</select>
</div></td>
</tr>
<tr>
<td>At-home essay on Olympia or Othello (25%):</td>
<td><input type="text" name="athome" size="10" maxlength="10">
</td>
<td><div align="right">
<select name="sel2" id="sel2">
<option selected>no</option>
<option>yes</option>
</select>
</div></td>
</tr>
<tr>
<td>2nd in-class essay on Poetry (20%):</td>
<td><input type="text" name="inclass2" size="10" maxlength="10">
</td>
<td><div align="right">
<select name="sel3" id="sel3">
<option selected>no</option>
<option>yes</option>
</select>
</div></td>
</tr>
<tr>
<td>Final exam (30%) : </td>
<td><input type="text" name="final" size="10" maxlength="10"></td>
<td><div align="right">
<select name="sel4" id="sel4">
<option selected>no</option>
<option>yes</option>
</select>
</div></td>
</tr>
<tr>
<td>Participation (10%) : </td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3"><table width="411" align="center">
<tr>
<td width="297">How many quizzes did you take? </td>
<td width="102"><select name="quiztaken" onChange="quizSel()">
<option selected>select</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select></td>
</tr>
<tr>
<td>Out of how many? </td>
<td><select name="totalquiz">
<option selected>select</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select></td>
</tr>
<tr>
<td><table width="211" align="center">
<tr>
<td width="203" colspan="3">
<div name="q" id="q" style="margin-bottom:4px;
display:none;"><strong>Enter your quiz scores below:</strong></div>
<div name="q1" id="q1"style="margin-bottom:2px; display:none;">
#1:
<span style="padding-left:4px; padding-right:4px;">
<input type="text" name="quiz1" size="8" maxlength="8">
</span>out of 5
</div>
<div name="q2" id="q2" style="margin-bottom:2px; display:none ">
#2:
<span style="padding-left:4px; padding-right:4px;">
<input type="text" name="quiz2" size="8" maxlength="8">
</span>out of 5
</div>
<div name="q3" id="q3" style="margin-bottom:2px; display:none ">
#3:
<span style="padding-left:4px; padding-right:4px;">
<input type="text" name="quiz3" size="8" maxlength="8">
</span>out of 5
</div>
<div name="q4" id="q4" style="margin-bottom:2px; display:none ">
#4:
<span style="padding-left:4px; padding-right:4px;">
<input type="text" name="quiz4" size="8" maxlength="8">
</span>out of 5
</div>
<div name="q5" id="q5" style="margin-bottom:2px; display:none ">
#5:
<span style="padding-left:4px; padding-right:4px;">
<input type="text" name="quiz5" size="8" maxlength="8">
</span>out of 5
</div>
</td>
</tr>
</table></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>How many Friday seminars have you missed? <a
href="javascript:popup1()">help</a></td>
<td><select name="semmissed">
<option selected>select</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select></td>
</tr>
<tr>
<td>Out of how many? <br>
<a href="javascript:popup1()">help</a> </td>
<td><select name="totalsem">
<option selected>select</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td height="35" colspan="3"><input value="Calculate Grade"
onclick="gradeCalc()" type="button"/>
<input value="Reset form"
onclick="javascript:document.gradeform.reset();history.go(0);return
false" type="button"/></td>
</tr>
<tr valign="middle">
<td height="35" colspan="3"> <span class="style2"> Note:
</span><br>
This is only an approximation. Scroll down for your grade
projection. </td>
</tr>
<tr>
<td height="35" colspan="3"><strong>Your grade projection: </
strong></td>
</tr>
<tr>
<td>Total score: </td>
<td><input name="score" type="text" id="score" size="10"
maxlength="10" style="font-weight:bold; color:#FF0000" readonly></td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="25">Out of total marks: </td>
<td><input name="total" type="text" id="total" size="10"
maxlength="10" style="font-weight:bold; color:#FF0000" readonly></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>You're currently on:</td>
<td><input name="grade" type="text" id="grade" size="10"
maxlength="10" style="font-weight:bold; color:#FF0000" readonly></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Your current percentile score: </td>
<td><input name="perc" type="text" id="perc" size="10"
maxlength="10" style="font-weight:bold; color:#FF0000" readonly></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3"><br>
<span class="style2"> Note: </span><br>
Click 'Reset Form' if you're having problems, and try again.
<br>
If you're still bugged drop a comment. </td>
</tr>
</table>
</form>

<script language="javascript1.4" type="text/javascript">
function gradeCalc() {
var sum = 0;
var whole = 0;
var xperc = 0;
var xgrade = 0;

sel1 = document.gradeform.sel1.value;
if (sel1 == "yes") {
inclass1 = document.gradeform.inclass1.value;
onSubmit(inclass1, "1st in-class essay");
inclass1 = parseFloat(inclass1);
if ((inclass1<0) || (inclass1>15)) throw(alert("Error: range
exceeded for 1st in-class essay"));
sum = sum + inclass1;
whole = whole + 15;
}
else document.gradeform.inclass1.value = "";

sel2 = document.gradeform.sel2.value;
if (sel2 == "yes") {
athome = document.gradeform.athome.value;
onSubmit(athome, "at-home essay");
athome = parseFloat(athome);
if ((athome<0) || (athome>25)) throw(alert("Error: range exceeded
for at-home essay"));
sum = sum + athome;
whole = whole + 25;
}
else document.gradeform.athome.value = "";

sel3 = document.gradeform.sel3.value;
if (sel3 == "yes") {
inclass2 = document.gradeform.inclass2.value;
onSubmit(inclass2, "2nd in-class essay");
inclass2 = parseFloat(inclass2);
if ((inclass2<0) || (inclass2>20)) throw(alert("Error: range
exceeded for 2nd in-class essay"));
sum = sum + inclass2;
whole = whole + 20;
}
else document.gradeform.inclass2.value = "";

sel4 = document.gradeform.sel4.value;
if (sel4 == "yes") {
final = document.gradeform.final.value;
onSubmit(final, "final exam");
final = parseFloat(final);
if ((final<0) || (final>30)) throw(alert("Error: range exceeded for
final exam"));
sum = sum + final;
whole = whole + 30;
}
else document.gradeform.final.value = "";

quiztaken = document.gradeform.quiztaken.value;
totalquiz = document.gradeform.totalquiz.value;
if (((quiztaken == "select") & !(totalquiz =="select"))|(!(quiztaken
== "select") & (totalquiz =="select")))
throw(alert("Error: illegal selection for quiz"));
if (!(quiztaken == "select") & !(totalquiz =="select")) {
if (quiztaken > totalquiz)
throw(alert("Error: illegal selection for quiz"));
}
if (quiztaken >= 1) {
quiztaken = parseInt(quiztaken);
totalquiz = parseInt(totalquiz);
whole = whole + totalquiz;

quiz1 = document.gradeform.quiz1.value;
onSubmit(quiz1, "quiz #1");
if ((quiz1<0) || (quiz1>5)) throw(alert("Error: range exceeded for
quiz #1"));
quiz1 = parseFloat(quiz1);
sum = sum + (quiz1/5);

if (quiztaken >= 2) {
quiz2 = document.gradeform.quiz2.value;
onSubmit(quiz2, "quiz #2");
if ((quiz2<0) || (quiz2>5)) throw(alert("Error: range exceeded for
quiz #2"));
quiz2 = parseFloat(quiz1);
sum = sum + (quiz2/5);

if (quiztaken >= 3) {
quiz3 = document.gradeform.quiz3.value;
onSubmit(quiz3, "quiz #3");
if ((quiz3<0) || (quiz3>5)) throw(alert("Error: range exceeded for
quiz #3"));
quiz3 = parseFloat(quiz3);
sum = sum + quiz3/5;

if (quiztaken >=4) {
quiz4 = document.gradeform.quiz4.value;
onSubmit(quiz4, "quiz #4");
if ((quiz4<0) || (quiz4>5)) throw(alert("Error: range exceeded
for quiz #4"));
quiz4 = parseFloat(quiz4);
sum = sum + quiz4/5;

if (quiztaken == 5) {
quiz5 = document.gradeform.quiz5.value;
onSubmit(quiz5, "quiz #5");
if ((quiz5<0) || (quiz5>5)) throw(alert("Error: range exceeded
for quiz #5"));
quiz5 = parseFloat(quiz5);
sum = sum + quiz5/5;
}
}
}
}
}

semmissed = document.gradeform.semmissed.value;
totalsem = document.gradeform.totalsem.value;
if (((semmissed == "select") & !(totalsem =="select"))|(!(semmissed
== "select") & (totalsem =="select")))
throw(alert("Error: illegal selection for seminars missed"));
if (!(semmissed == "select") & !(totalsem =="select")) {
if (semmissed > totalsem)
throw(alert("Error: illegal selection for seminars missed"));
}
if ((semmissed != "select") & (totalsem !="select")) {
semmissed = parseInt(semmissed);
totalsem = parseInt(totalsem);

semmissed = semmissed*(0.5);
totalsem = totalsem*(0.5)
sum = sum + (totalsem-semmissed);
whole = whole + totalsem;
}

xperc = sum/whole * 100;

if ((xperc>89) && (xperc<=100)) xgrade ='A+';
else if((xperc>84) && (xperc<=89)) xgrade ='A';
else if((xperc>79) && (xperc<=84)) xgrade ='A-';
else if((xperc>75) && (xperc<=79)) xgrade ='B+';
else if((xperc>71) && (xperc<=75)) xgrade ='B';
else if((xperc>67) && (xperc<=71)) xgrade ='B-';
else if((xperc>63) && (xperc<=67)) xgrade ='C+';
else if((xperc>59) && (xperc<=63)) xgrade ='C';
else if((xperc>54) && (xperc<=59)) xgrade ='C-';
else if((xperc>49) && (xperc<=54)) xgrade ='D';
else if((xperc>=0) && (xperc<=49)) xgrade ='F';
else throw(alert("Error: invalid data"));

xperc = Math.round(xperc*Math.pow(10,3))/Math.pow(10,3);

document.gradeform.score.value = sum;
document.gradeform.total.value = whole;
document.gradeform.grade.value = xgrade;
document.gradeform.perc.value = xperc+"%";
}

function onSubmit(value, id) {
this.value = value;
this.id = id;
if (isNaN(value) || (value == "")) {
throw(alert("Error: invalid entry for \""+id+"\", only numerical
score allowed"));
}
}

function quizSel() {
quiztaken = document.gradeform.quiztaken.value;

if (quiztaken == 1) {
document.getElementById("q").style.display = "block";
document.getElementById("q1").style.display = "block";
document.getElementById("q2").style.display = "none";
document.gradeform.quiz2.value = "";
document.getElementById("q3").style.display = "none";
document.gradeform.quiz3.value = "";
document.getElementById("q4").style.display = "none";
document.gradeform.quiz4.value = "";
document.getElementById("q5").style.display = "none";
document.gradeform.quiz5.value = "";
return;
}
if (quiztaken == 2) {
document.getElementById("q").style.display = "block";
document.getElementById("q1").style.display = "block";
document.getElementById("q2").style.display = "block";
document.getElementById("q3").style.display = "none";
document.gradeform.quiz3.value = "";
document.getElementById("q4").style.display = "none";
document.gradeform.quiz4.value = "";
document.getElementById("q5").style.display = "none";
document.gradeform.quiz5.value = "";
return;
}
if (quiztaken == 3) {
document.getElementById("q").style.display = "block";
document.getElementById("q1").style.display = "block";
document.getElementById("q2").style.display = "block";
document.getElementById("q3").style.display = "block";
document.getElementById("q4").style.display = "none";
document.gradeform.quiz4.value = "";
document.getElementById("q5").style.display = "none";
document.gradeform.quiz5.value = "";
return;
}
if (quiztaken == 4) {
document.getElementById("q").style.display = "block";
document.getElementById("q1").style.display = "block";
document.getElementById("q2").style.display = "block";
document.getElementById("q3").style.display = "block";
document.getElementById("q4").style.display = "block";
document.getElementById("q5").style.display = "none";
document.gradeform.quiz5.value = "";
return;
}
if (quiztaken == 5) {
document.getElementById("q").style.display = "block";
document.getElementById("q1").style.display = "block";
document.getElementById("q2").style.display = "block";
document.getElementById("q3").style.display = "block";
document.getElementById("q4").style.display = "block";
document.getElementById("q5").style.display = "block";
return;
}

document.getElementById("q").style.display = "none";
document.getElementById("q1").style.display = "none";
document.gradeform.quiz1.value = "";
document.getElementById("q2").style.display = "none";
document.gradeform.quiz2.value = "";
document.getElementById("q3").style.display = "none";
document.gradeform.quiz3.value = "";
document.getElementById("q4").style.display = "none";
document.gradeform.quiz4.value = "";
document.getElementById("q5").style.display = "none";
document.gradeform.quiz5.value = "";

return;
}

function popup1() {
popup1 = window.open("", "popup1", "status = 1, left = 300, top =
200, width = 450, height = 250, scrollbars = 1");
popup1.document.write("<html><head><title>Seminar dates</title></
head>");
popup1.document.write("<body><b><u>Seminar dates for ENGL 110.005,
Winter 2 term, 2008:</b></u><br/><br/>");
popup1.document.write("Fri, Jan. 11: Discussion group on Simple
Recipes (1-53)<br/>");
popup1.document.write("Fri, Jan. 18: Discussion group on Simple
Recipes (55-125)<br/><br/>");
popup1.document.write("Fri, Feb. 01: Discussion group on Olympia
(1-122)<br/>");
popup1.document.write("Fri, Feb. 08: Discussion group on Olympia
(123-195) said:
popup1.document.write("Fri, Feb. 29: Discussion Group on Othello<br/
popup1.document.write("Fri, Mar. 07: Discussion group on Mom, Dad,
I'm Living With a White Girl<br/>");
popup1.document.write("Fri, Mar. 14: Discussion group on Ondaatje
and Gill<br/><br/>");
popup1.document.write("Fri, Apr. 04: Discussion group on Diamond
Grill<br/>");
popup1.document.write("Fri, Apr. 11: Last day of classes; last
discussion group</body></html>");
popup1.document.close();
}

</script>
<p>&nbsp;</p>
</body>
</html>
 
C

cwdjrxyz

Thanks to everyone who replied to this post. I've updated the page on
my blog to reflect my current status regarding this issue (http://
techqi.blogspot.com/2008/02/beta.html).

Anyway, I'm lost and I'm no expert. Never used Firebug etc. I'm
pasting the code below, works fine on my system:
--------------------------------------

I am not repeating the long code you give. Rather I put it up on the
web for a short time so you or others can test it. It is at
http://www.cwdjr.net/test/althtmltest.html . Often when you copy code
this long from a NG post there are errors so it is quite possible that
a few errors have been introduced compared to what you have on your
computer. If you validate the page, you are down to only 12 validation
errors - a great improvement. However the page does not work properly
locally on my computer or on the web at the posted url. You can input
data into the form and erase it. However the calculation is not being
made and reported . If you use IE7 for the web version, and clear the
form with the button, you get a script error warning asking if you
wish to continue using script. If you use Firefox and turn on the
error console, you get some script errors concerning an undetermined
string literal, among other things. If you use Opera and go to tools >
advanced > error console, you get a syntex error loading line 13. Thus
it would appear that there are script errors in the portion of the
program that calculates the grades. Script is much more exacting than
html, and even one small error can completely kill the script. Thus it
might take quite a while to determine exactly what the problems in the
script are. Again, copying the code from a NG post may have introduced
an error or two.
 
T

tashfeenmahmud

Hey thanks, but I managed to fix it. Sorry I didn't check your post
earlier. Take care, and sorry for the long post last time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top