计算未附加

时间:2017-02-01 19:35:01

标签: jquery function calculation

我在使用函数计算并附加到输入字段下面的di(#results)时遇到问题。如果结果没有附加,我甚至不确定我的计算是否正确和有效。我在这方面有点新,我迷路了。我已经让我的大脑呆了大约一个星期了,但仍然一无所获。有人可以帮助指导我纠正这个问题。谢谢你,祝你有个美好的一天。

function getgpa()
{//puts credit hours to zero if left blank
var curgpa = document.getElementById('curgpa').value;
var allcrhrs = document.getElementById('allcrhrs').value;

// gets grade points
var g1 = document.getElementById('G1').value;
var g2 = document.getElementById('G2').value;
var g3 = document.getElementById('G3').value;
var g4 = document.getElementById('G4').value;
var g5 = document.getElementById('G5').value;
var g6 = document.getElementById('G6').value;
var g7 = document.getElementById('G7').value;
var g8 = document.getElementById('G8').value;

// gets credit hours
var cr1 = document.getElementById('CR1').value;
var cr2 = document.getElementById('CR2').value;
var cr3 = document.getElementById('CR3').value;
var cr4 = document.getElementById('CR4').value;
var cr5 = document.getElementById('CR5').value;
var cr6 = document.getElementById('CR6').value;
var cr7 = document.getElementById('CR7').value;
var cr8 = document.getElementById('CR8').value; 
//end of credit hours

//AcademicGpaForm new grade points

//AcademicGpaForm new credit hours

//checking if class was repeated
//***rgpts = repeat grade points***
//***rcrhrs = repeat creadits (in hours)*** 
if (document.getElementById('chk1').checked == true)
    {
        rqpts1 = (document.getElementById('cr1') * document.getElementById('RG1').value);
        rcrhrs1 = cr1;
    }
if (document.getElementById('chk2').checked == true)
    {
        rqpts2 = (cr2 * document.getElementById('RG2').value);
        rcrhrs2 = cr2;
    }
if (document.getElementById('chk3').checked == true)
    {
        rqpts3 = (cr3 * document.getElementById('RG3').value);
        rcrhrs3 = cr3;
    }
if (document.getElementById('chk4').checked == true)
    {
        rqpts4 = (cr4 * document.getElementById('RG4').value);
        rcrhrs4 = cr4;
    }
if (document.getElementById('chk5').checked == true)
    {
        rqpts5 = (cr5 * document.getElementById('RG5').value);
        rcrhrs5 = cr5;
    }
if (document.getElementById('chk6').checked == true)
    {
        rqpts6 = (cr6 * document.getElementById('RG6').value);
        rcrhrs6 = cr6;
    }
if (document.getElementById('chk7').checked == true)
    {
        rqpts7 = (cr7 * document.getElementById('RG7').value);
        rcrhrs7 = cr7;
    }
if (document.getElementById('chk8').checked == true)
    {
        rqpts8 = (cr8 * document.getElementById('RG8').value);
        rcrhrs8 = cr8;
    }
 // repeatgpa = (((cumgpa * allchrs)-oldgpts)+newgpts)/(allchrs + newchrs)

//AcademicGpaForm new credit hours
var newcrhrs = (parseFloat(cr1) + parseFloat(cr2) + parseFloat(cr3) + parseFloat(cr4) + parseFloat(cr5) + parseFloat(cr6) + parseFloat(cr7) + parseFloat(cr8));

//AcademicGpaForm new grade points
var newgpts = ((parseFloat(cr1) * parseFloat(g1)) + (parseFloat(cr2) * parseFloat(g2)) + (parseFloat(cr3) * parseFloat(g3)) + (parseFloat(cr4) * parseFloat(g4)) + (parseFloat(cr5) * parseFloat(g5)) + (parseFloat(cr6) * parseFloat(g6)) + (parseFloat(cr7)  *parseFloat(g7)) + (parseFloat(cr8) * parseFloat(g8)));

//AcademicGpaForm old grade points (repeat grade points)
var oldgpts = (parseFloat(rqpts1) + parseFloat(rqpts2) + parseFloat(rqpts3) + parseFloat(rqpts4) + parseFloat(rqpts5) + parseFloat(rqpts6) + parseFloat(rqpts7) + parseFloat(rqpts8));

//AcademicGpaForm old credit hours (repeat credit hours)
var oldcrhrs = (parseFloat(rcrhrs1) + parseFloat(rcrhrs2) + parseFloat(rcrhrs3) + parseFloat(rcrhrs4) + parseFloat(rcrhrs5) + parseFloat(rcrhrs6) + parseFloat(rcrhrs7) + parseFloat(rcrhrs8));

//AcademicGpaForm gpa
var finalgpts = (((parseFloat(curgpa) * parseFloat(allcrhrs)) - parseFloat(oldgpts)) + parseFloat(newgpts));
var finalcrhrs = ((parseFloat(newcrhrs) - parseFloat(oldcrhrs)) + parseFloat(allcrhrs));

var gpa = (parseFloat(finalgpts) / parseFloat(finalcrhrs));
$("#results").append((parseFloat(gpa) * 1000)/1000);
//document.AcademicGpaForm.Text1.value = Math.round(gpa * 1000)/1000;
}

function clear_all()
{
//clears all values on the form
document.getElementById('RG1').value = "";
document.getElementById('RG2').value = "";
document.getElementById('RG3').value = "";
document.getElementById('RG4').value = "";
document.getElementById('RG5').value = "";
document.getElementById('RG6').value = "";
document.getElementById('RG7').value = "";
document.getElementById('RG8').value = "";

document.getElementById('G1').value = "";
document.getElementById('G2').value = "";
document.getElementById('G3').value = "";
document.getElementById('G4').value = "";
document.getElementById('G5').value = "";
document.getElementById('G6').value = "";
document.getElementById('G7').value = "";
document.getElementById('G8').value = "";

document.getElementById('chk1').checked = false;
document.getElementById('chk2').checked = false;
document.getElementById('chk3').checked = false;
document.getElementById('chk4').checked = false;
document.getElementById('chk5').checked = false;
document.getElementById('chk6').checked = false;
document.getElementById('chk7').checked = false;
document.getElementById('chk8').checked = false;

document.getElementById('CR1').value = "";
document.getElementById('CR2').value = "";
document.getElementById('CR3').value = "";
document.getElementById('CR4').value = "";
document.getElementById('CR5').value = "";
document.getElementById('CR6').value = "";
document.getElementById('CR7').value = "";
document.getElementById('CR8').value = "";

document.getElementById('curgpa').value = "";
document.getElementById('allcrhrs').value = "";

// ******No 'Text1' in this document
document.getElementById('Text2').value = "";
document.getElementById('Text3').value = "";
document.getElementById('Text4').value = "";
document.getElementById('Text5').value = "";
document.getElementById('Text6').value = "";
document.getElementById('Text7').value = "";
document.getElementById('Text8').value = "";
document.getElementById('Text9').value = "";
}

function set_txtval ()
{
if (document.getElementById('curgpa').value == "")
{
    document.getElementById('curgpa').value = 0;
}
if (document.getElementById('allcrhrs').value == "")
{
    document.getElementById('allcrhrs').value = 0;
}
if (document.getElementById('CR1').value == "")
{
    document.getElementById('CR1').value = 0;
}
if (document.getElementById('CR2').value == "")
{
    document.getElementById('CR2').value = 0;
}
if (document.getElementById('CR3').value == "")
{
    document.getElementById('CR3').value = 0;
}

if (document.getElementById('CR4').value == "")
{
    document.getElementById('CR4').value = 0;
}

if (document.getElementById('CR5').value == "")
{
    document.getElementById('CR5').value = 0;
}
if (document.getElementById('CR6').value == "")
{
    document.getElementById('CR6').value = 0;
}

if (document.getElementById('CR7').value == "")
{
    document.getElementById('CR7').value = 0;
}

if (document.getElementById('CR8').value == "")
{
    document.getElementById('CR8').value = 0;
}

if (document.getElementById('CR1').value == "")
{
    document.getElementById('CR1').value = 0;
}
}
</script>

//The code below is the text and fields that need input and then are calculated and appended into the bottom div.
<body>
<h1>How to Calculate Your Projected GPA </h1>
<hr>
<p><strong>What are your cumulative credit hours?    </strong>&nbsp;&nbsp;<INPUT type="text" id="allcrhrs" />
<EM>*To find, obtain your   unofficial transcript on <A href="https://sail.ncmissouri.edu/" target="_blank">SAIL</A>. Cumulative credit hours will be listed under 'GPA Crd Cum' listed after your last semester of attendance.  If this is your first semester, indicate a 0.</EM></p>
<p><strong>What is your cumulative GPA?</strong>&nbsp;&nbsp;<INPUT type="text" id="curgpa" /></p>
<table class="degreeTable" align="center" id="AcademicGpaForm">
<tbody>
<tr><th><STRONG>Course Name</STRONG></th>
<th><STRONG>Credit Hours</STRONG></th>
<th><STRONG>Grade</STRONG></th>
<th><STRONG>Repeat?</STRONG></th>
<th><STRONG>Old Grade if  Repeated</STRONG></th>
</tr>
<tr><td><INPUT type="text" id="Text2" /></td>
<td><INPUT type="text" id="CR1" /></td>
<td><SELECT id="G1">     <OPTION selected value=""></OPTION>    <OPTION  value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>    </SELECT></td>
<td><INPUT type="checkbox" id="chk1" /></td>
<td><SELECT id="RG1">     <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>     </SELECT></td>
</tr>
<tr><td><INPUT type="text" id="Text3" /></td>
<td><INPUT type="text" id="CR2" /></td>
<td><SELECT id="G2">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>    </SELECT></td>
<td><INPUT type="checkbox" id="chk2" /></td>
<td><SELECT id="RG2">     <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>    </SELECT></td>
</tr>
<tr><td><INPUT type="text" id="Text4" /></td>
<td><INPUT type="text" id="CR3" /></td>
<td><SELECT id="G3">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>     <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>     <OPTION value="0">F</OPTION>    </SELECT></td>
<td><INPUT type="checkbox" id="chk3" /></td>
<td><SELECT id="RG3">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>    </SELECT></td>
</tr>
<tr><td><INPUT type="text" id="Text5" /></td>
<td><INPUT type="text" id="CR4" /></td>
<td><SELECT id="G4">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>     </SELECT></td>
<td><INPUT type="checkbox" id="chk4" /></td>
<td><SELECT id="RG4">     <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>    </SELECT></td>
</tr>
<tr><td><INPUT type="text" id="Text6" /></td>
<td><INPUT type="text" id="CR5" /></td>
<td><SELECT id="G5">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>     </SELECT></td>
<td><INPUT type="checkbox" id="chk5" /></td>
<td><SELECT id="RG5">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>    </SELECT></td>
</tr>
<tr><td><INPUT type="text" id="Text7" /></td>
<td><INPUT type="text" id="CR6" /></td>
<td><SELECT id="G6">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>    </SELECT></td>
<td><INPUT type="checkbox" id="chk6" /></td>
<td><SELECT id="RG6">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>     </SELECT></td>
</tr>
<tr><td><INPUT type="text" id="Text8" /></td>
<td><INPUT type="text" id="CR7" /></td>
<td><SELECT id="G7">     <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>     <OPTION value="0">F</OPTION>     </SELECT></td>
<td><INPUT type="checkbox" id="chk7" /></td>
<td><SELECT id="RG7">     <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>    </SELECT></td>
</tr>
<tr><td><INPUT type="text" id="Text9" /></td>
<td><INPUT type="text" id="CR8" /></td>
<td><SELECT id="G8">     <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>    <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>    <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION>     </SELECT></td>
<td><INPUT type="checkbox" id="chk8" /></td>
<td><SELECT id="RG8">    <OPTION selected value=""></OPTION>    <OPTION value="4">A</OPTION>     <OPTION value="3">B</OPTION>    <OPTION value="2">C</OPTION>     <OPTION value="1">D</OPTION>    <OPTION value="0">F</OPTION></SELECT></td>
</tr>
</tbody>
</table>
<p align="center">    <INPUT onclick="getgpa()" type="button" value="gpa" id="Button1" />&nbsp;    <INPUT onclick="clear_all()" type="button" value="Clear" id="Button2" /></p>
<div id="results" name="resultsDiv"></div>
</body>

0 个答案:

没有答案