需要GPA和CGPA计算代码

时间:2012-05-25 23:03:57

标签: javascript

我有一些代码,但代码缺少一些功能。
 1.如果我们选择了盒子,而不是计算  2.如果我们在重复课程中选择是的值。我们如何计算新的     gpa和cgpa?

脚本代码

<script type = "text/javascript">

//function to set the focus on GPA form 
function setFocus() { 
document.GPA.focus(); 
return; 
}


//functio to round 2 decimal points 
function round(n){return(.01* Math.round(100*n));}



//function to calculate gpa 
function calculate(fr) 
{ 





//checking if all credit hours equal to zero 
if (fr.CH1.selectedIndex=="0") 
{alert ("Please specify your credit hours") } 



else 

//calculating 
var resultgpa; 
fr.resultgpa.value=round((eval(fr.CH1.selectedIndex)*parseFloat(fr.grade1.value))
/(eval(fr.CH1.selectedIndex)))

var resultcgpa; 
fr.resultcgpa.value 
=round((eval(fr.CH1.selectedIndex)*parseFloat(fr.grade1.value)+ 
parseFloat(fr.cgpa.value)*parseFloat(fr.TCH.value)) 
/(eval(fr.CH1.selectedIndex)+ 
parseFloat(fr.TCH.value)))



}


</script>

HTML代码:

<form action="none" name="GPA">
<table  width="700" border="3"  align="center" valign="top" > 
<!--creating form to send data to function--> 


    <tr><td><p align="center"style="font-size:16pt"><b>Select</b></p></td>
    <td><p align="center"style="font-size:16pt"><b>Courses</b></p></td>
    <td><p align="center"style="font-size:16pt"><b>Credit</b></p></td>
    <td><p align="center"style="font-size:16pt"><b>Expected/Grade</b></p></td>
    <td><p align="center"style="font-size:16pt"><b>Repeted Course</b></p></td>
    <td><p align="center"style="font-size:16pt"><b>Previous Grade</b></p></td></tr>

<tr> 
<td>1. <input type="checkbox" text name="sn1"value="smoker"/></td>
<td><select name="c1">
<option value="unknown">Select</option>
<option>CPE 101</option>
<option>ENG 101</option>
<option>ECO 101</option>
<option>MAT 101</option>
<option>PHY 101</option>
<option>HTR 101</option>
<option>TUR 101</option>
<option>CPE 112</option>
<option>ENG 102</option>
<option>MAT 102</option>
<option>PHY 102</option>
<option>CHM 110</option>
<option>CPE 221</option>
<option>CLE 201</option>
<option>CLE 201</option>
<option>MAT 201</option>
<option>MAT 205</option>
<option>XXX XXX</option>
<option>CPE 222</option>
<option>ILE 224</option>
<option>ILE 212</option>
<option>ILE 232</option>
<option>MAT 204</option>
<option>CPE 313</option>
<option>CPE 321</option>
<option>CPE 331</option>
<option>CPE 351</option>
<option>CPE 341</option>
<option>CPE 326</option>
<option>CPE 332</option>
<option>CPE 342</option>
<option>CPE 324</option>
<option>CPE 322</option>
<option>CPE 411</option>
<option>CPE 413</option>
<option>CPE 415</option>
<option>CPE 400</option>
<option>CPE 414</option>
<option>CPE 415</option>
</select></td>
<td align = "center"> 
<select name= "CH1"> 
<option value = "0" SELECTED>Select 
<option value = "1">1 
<option value = "2">2 
<option value = "3">3 
<option value = "4">4

</select></td>

<td align = "center" width = "70"> 
<select name= "grade1"> 
<option value = "5" SELECTED>Select 
<option value = "4">A 
<option value = "3.70">A- 
<option value = "3.30">B+ 
<option value = "3">B 
<option value = "2.70">B- 
<option value = "2.30">C+ 
<option value = "2">C 
<option value = "1.70">C- 
<option value = "1.30">D+ 
<option value = "1">D
<option value = "0.7">D-  
<option value = "0">F
</select></td>

    <td> <center>
         <input type="radio" name="1">Yes
         <input type="radio" name="1">No
    </center></td>

<td align = "center"> 
<select name= "g1"> 
<option value = "5" SELECTED>Select 
<option value = "4">A 
<option value = "3.70">A- 
<option value = "3.30">B+ 
<option value = "3">B 
<option value = "2.70">B- 
<option value = "2.30">C+ 
<option value = "2">C 
<option value = "1.70">C- 
<option value = "1.30">D+ 
<option value = "1">D
<option value = "0.7">D-  
<option value = "0">F

</select></td>
</tr>
</table>
<table width="400" border="3" align="center" valign="top"> 


<tr> 
<td><p align="center"style="font-size:16pt"><b> Your Current CGPA:</b></p> </td><td align="right"><input type = text name="cgpa"></td></tr>

<tr><td><p align="center"style="font-size:16pt"><b>Your Credit Hours Taken Is:</b></p> </td><td align="right"><input type = text name="TCH"></td></tr>

</table>

<table width="400" border="3" align="center" valign="top"> 





<!--sending information to calculate() function-->

<!--getting back result from function--> 
<tr><td><p align="center"style="font-size:16pt"><b>Your GPA Will Be:</b></p></td> 
<td align="right"><input type = text name="resultgpa"></td></tr>

<!--getting back result from function--> 
<tr><td><p align="center"style="font-size:16pt"><b>Your CPGA Will Be:</b></p></td> 
<td align="right"><input type = text name="resultcgpa"></td></tr>

<tr><td><input type = "button" value = "Calculate!" onclick = "calculate(this.form)" name = "bottun"></td>

<!--reset button--> 
<td align="right"><input type="reset" name="reset" value="Clear">

</td></tr> 
</table>
</form>

0 个答案:

没有答案