Thursday, March 15, 2012

Result Calculator

This javascript generates the result of the student. It gives total, percentage and grade in the output for the marks of 5 subjects enetered as input.
Following is the javascript for the same.

<html>
<head>
<script language="javascript" type="text/javascript" />
function ok()
{
    name=(document.f1.t1.value);
    rollno=(document.f1.t2.value);
   
    a=Number(document.f1.t3.value);
    b=Number(document.f1.t4.value);
    c=Number(document.f1.t5.value);
    d=Number(document.f1.t6.value);
    e=Number(document.f1.t7.value);
   
    if(a<=0 || a>100)
        alert("the value of marks 1 is invalid");
    if(b<=0 || b>100)
        alert("the value of marks 2 is invalid");   
    if(c<=0 || c>100)
        alert("the value of marks 3 is invalid");
    if(d<=0 || d>100)
        alert("the value of marks 4 is invalid");
    if(e<=0 || e>100)
        alert("the value of marks 5 is invalid");
    total=a+b+c+d+e;
    t=document.f1.t8.value=total;
    per=total/5;
    p=document.f1.t9.value=per;
   
    if(per>=80)
        document.f1.t10.value="AA";
    else if(per>=70 && per<80)
        document.f1.t10.value="BB";
    else if(per>=60 && per<70)
        document.f1.t10.value="cc";
    else
        document.f1.t10.value="fail";
}   
 </script>
</head>
<body>
<form name="f1">
Name
<input type="text" name="t1" />
<br />
roll no
<input type="text" name="t2" />
<br />
marks1
<input type="text" name="t3" />
<br />
marks2
<input type="text" name="t4" />
<br />
marks3
<input type="text" name="t5" />
<br />
marks4
<input type="text" name="t6" />
<br />
marks5

<input type="text" name="t7" />
<br />
total
<input type="text" name="t8" />
<br />
percentage
<input type="text" name="t9" />
<br />
grade
<input type="text" name="t10" />

<br />
<input type="button" value="ok" onclick="ok();" />
 </body>
</html>

No comments:

Post a Comment