...

View Full Version : Student Grade help.



jace_co_uk
02-28-2012, 01:34 PM
i wold like to get this working. when a user enters 4 grades into the text boxes. it would give them the Avg Grade and also what Mark they got,

and if they failed one out put the module they most Repeat and if they passed all out put a smiley face..

This is what i have so far..



function compute() {

var c = document.getElementById("c").value;

var computer = document.getElementById("computer").value;

var web = document.getElementById("web").value;

var math = document.getElementById("math").value;







document.getElementById("cost").value =

totalCost = (c * 100 + computer * 100 + web * 100 + math * 100 ) /4;


if(cost >=93)
alert(" You got an A+")
else
if((cost >=85)&(grade <93))
alert(" You got an A")
else
if((cost >=78)&(grade <85))
alert(" You got an B")
else
if((cost >=60)&(grade <78))
alert(" You got an C")
else
if((cost >=40)&(grade <60))
alert(" You got an D")
else
if(cost <40)
alert(" You Failed this Module")


</script>
</head>
<body>

<form method="get" action="" onsubmit='return formValidator()' >
<fieldset id="personalInfo">

<h3> Student Results </h3>



<!-- A bordered table for item orders -->



<table border = "border">



<!-- First, the column headings -->



<tr>

<th> Module Name </th>

<th> Pass Mark </th>

<th> Final Mark </th>

</tr>



<!-- Now, the table data entries -->



<tr>

<th> C++ </th>

<td> 40 % </td>

<td> <input type = "text" id = "c"

size ="10" /> </td>

</tr>

<tr>

<th> Computer Systems </th>

<td> 40 % </td>

<td> <input type = "text" id = "computer"

size = "10" /> </td>

</tr>

<tr>

<th> Web Development </th>

<td> 40 % </td>

<td> <input type = "text" id = "web"

size = "10" /></td>

</tr>
<tr>

<th> Maths </th>

<td> 40 % </td>

<td> <input type = "text" id = "math"

size ="10" /> </td>

</tr>

</table>



<!-- Button for precomputation of the total cost -->



<p>

<input type = "button" value = "Total Grade"

onclick = "compute();" />

<input type = "text" size = "5" id = "cost"

onfocus = "this.blur();" />

</p>









</fieldset>
</p>
<input type='submit' value='Check Form' />

</form>
</body>
</html>

devnull69
02-28-2012, 01:43 PM
You have a total of 5 variables in your code (c, computer, web, math and totalCost). But you are comparing a variable "cost" to get the grade. I think you should replace "cost" with "totalCost" down there.

jace_co_uk
02-28-2012, 03:45 PM
The Total Cost is the Vaule of the Button that gives the GPA,

was thinking of just making it simpler..
how would i get a popup after i enter in the value that states you got an A or a F

Philip M
02-28-2012, 04:25 PM
var c = document.getElementById("c").value;

Do not use the same name for an HTML element and a Javascript variable.

It is obvious that you have copied this from somewhere with no attempt to make the variable names something sensible. What has "cost" to do with student grades?

Name your textboxes Subject1, Subject2 etc. or better the actual subject names.


var grade = "Failed";
if (totalmark >=40) {grade = "D"}
if (totalmark >=60) {grade = "C"}
if (totalmark >=78) {grade = "B"}
if (totalmark >=85) {grade = "A"}
if (totalmark >=93) {grade = "A+"}
alert ("Your grade is " + grade);

What if the user enters nonsense (or nothing at all) into the textboxes?

I used to go to church religiously. - Interviewee BBC Radio 4

jace_co_uk
02-28-2012, 05:19 PM
Yes i have copy a bit of the code,

from Example labs that were given to us in web development

if the user enters in nothing or nonsense i have some JS functions that will stop them

I have no problem with that part but its getting the popup box up as they enter in a mark to give them an A or F

i have change this around..
so i not getting the GPA just want a alert box to pop up after they enter their Mark





Enter Semester: <br />
<input type='text' id='semester' placeholder="Enter Seemster"/>
</p>
<p>
Module Results: <br />
<select id='course1'>
<option>Please Choose</option>
<option value="c">C++</option>
<option value="java">Java 1</option>
<option value="java2">Java 2</option>
<option value="hard">Computer HardWare</option>
<option value="data">DataBase System 1</option>
<option value="data2">DataBase System 2</option>
<option value="system">System Administration 1</option>
</select><br />
<input type='text' id='module1' placeholder="Enter Module Results"/>
</p>
<p>
<select id='course2'>
<option>Please Choose</option>
<option value="c">C++</option>
<option value="java">Java 1</option>
<option value="java2">Java 2</option>
<option value="hard">Computer HardWare</option>
<option value="data">DataBase System 1</option>
<option value="data2">DataBase System 2</option>
<option value="system">System Administration 1</option>
</select><br />
<input type='text' id='module2' placeholder="Enter Module Results"/>
</p>
<p>
<select id='course3'>
<option>Please Choose</option>
<option value="c">C++</option>
<option value="java">Java 1</option>
<option value="java2">Java 2</option>
<option value="hard">Computer HardWare</option>
<option value="data">DataBase System 1</option>
<option value="data2">DataBase System 2</option>
<option value="system">System Administration 1</option>
</select><br />
<input type='text' id='module3' placeholder="Enter Module Results"/>
</p>
<p>
<select id='course4'>
<option>Please Choose</option>
<option value="c">C++</option>
<option value="java">Java 1</option>
<option value="java2">Java 2</option>
<option value="hard">Computer HardWare</option>
<option value="data">DataBase System 1</option>
<option value="data2">DataBase System 2</option>
<option value="system">System Administration 1</option>
</select><br />
<input type='text' id='module4' placeholder="Enter Module Results"/>
</p>

</fieldset>
</p>
<input type='submit' value='Check Form' />

Philip M
02-28-2012, 06:06 PM
<input type='text' size = "3" maxlength = "3" id='module1' onblur = "show(this)" placeholder="Enter Module Results"/>
<input type='text' size = "3" maxlength = "3" id='module2' onblur = "show(this)" placeholder="Enter Module Results"/>
<input type='text' size = "3" maxlength = "3" id='module3' onblur = "show(this)" placeholder="Enter Module Results"/>

<script type = "text/javascript">

function show(which) {
var mark = parseInt(which.value,10) || 0; // trap non-numeric entries, make number integer
if (mark >100) {mark == 100} // maximum 100
which.value = mark; // write it back to the field
var mod = which.id;
var grade = "Failed";
if (mark >=40) {grade = "D"}
if (mark >=60) {grade = "C"}
if (mark >=78) {grade = "B"}
if (mark >=85) {grade = "A"}
if (mark >=93) {grade = "A+"}
alert ("Your grade for " + mod + " is " + grade);
}

</script>

jace_co_uk
02-28-2012, 07:00 PM
Thanks alot..

i'll mess around with this one function.. and see what else i could add to it



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum