6 Replies - 773 Views - Last Post: 30 October 2013 - 08:30 PM

#1 headmasterofsoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-October 13

script for calculating quality points from units and letter grade

Posted 29 October 2013 - 06:53 PM

New to using javascript, am using Adobe Acrobat Pro 9 to create an Editable Form for use by students when advising.
I have set up fields for every course taken (ID Course), for credit hours attempted (HA Course), credit hours earned (HE Course), and letter grade (GRD Course) for all required classes...I have created a fourth field in the row for "Quality Points" (QP Course).
Adobe Acrobat Pro allows you to create a "custom calculation script" for any field created. It needs to be in javascript.
I am trying to tell it take the credit hours earned, and multiply to the third field - but I need it to convert Grade to points first. It is a fairly simple/straightforward conversion:

if (grade=="A")point=4;

if (grade=="B")point=3;

if (grade=="C")point=2;

if (grade=="D")point=1;

if (grade=="F")point=0;

but I need to script that conversion into the calculation - multiply by hours earned (HE course)

Can someone help with this custom calculation script?

It would make a whole lot of students a lot happier, not having to multiple in their heads (many are not so good with math...sigh, they are communication students). I fear the errors if I do not specify the value for Quality Points with an automatic calculation, that the Overall GPA will be incorrect accordingly (Which I have already figured out how to calculate). Thanks for your time. Jeff

Is This A Good Question/Topic? 0
  • +

Replies To: script for calculating quality points from units and letter grade

#2 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: script for calculating quality points from units and letter grade

Posted 29 October 2013 - 07:46 PM

See if you can modify this to your needs ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />

<title> Untitled </title>

</head>
<body>
<!--
I have set up fields for every course taken (ID Course),
 for credit hours attempted (HA Course),
 credit hours earned (HE Course),
 and letter grade (GRD Course) for all required classes
...
I have created a fourth field in the row for "Quality Points" (QP Course).
...
but I need to script that conversion into the calculation - multiply by hours earned (HE course)
-->

<input id="IDcourse" value="Course ID"> Course ID<br>
<input id="HAcourse" value=""> Hours attempted <br>
<input id="HEcourse" value=""> Hours earned<br>
<input id="GRDcourse" value=""> Grade (A..F)<br>
<input id="QPcourse" value="" readonly onclick="QPcalc()"> Quality Points<br>

<script type="text/javascript">
// For: http://www.dreamincode.net/forums/topic/332801-script-for-calculating-quality-points-from-units-and-letter-grade/

function $_(IDS) { return document.getElementById(IDS); };
function QPcalc() {
  var HE = Number($_('HEcourse').value);
  var GRD = $_('GRDcourse').value.toUpperCase();
  var QP;
  switch (GRD) {
    case 'A': QP = HE * 4; break;
    case 'B': QP = HE * 3; break;
    case 'C': QP = HE * 2; break;
    case 'D': QP = HE * 1; break;
    case 'F': QP = HE * 0; break;
     default: alert('Invalid Grade assignment'); QP = 0; break;
  }
  $_('QPcourse').value = QP;
}
window.onload = function() {
  $_('HAcourse').value = 20;
  $_('HEcourse').value = 15;
  $_('GRDcourse').value = 'A';
}
</script>

</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#3 headmasterofsoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-October 13

Re: script for calculating quality points from units and letter grade

Posted 30 October 2013 - 09:45 AM

Not working, nothing comes up - stays blank.
I think that fact I am working with a PDF application, Acrobat Pro 9 and not a web application, is going to make this script different. While not well versed in javascript, I do know about html code (I teach a web design course using Dreamweaver, make the student learn basic html code to troubleshoot).
I am also working with Apple Software, but I don't think that affected the fact it doesn't want to work.
Here is an example of the custom calculation script that does work, it does calculate the value for a field I created to calculating the overall GPA:

event.value = ( this.getField("QP TOTAL COM").value ) / this.getField("HA TOTAL COM").value;

Do you think I need to alter the terminology to identify the final calculation as an "event.value"

I would also be willing to create a separate field (column line) on the form, for each course, that converts the grade to points first...I can probably make the field window so small that it will not show or print on the actual form itself.
That way it would be a simple multiplication of two existing fields, which I am pretty sure I know how to do.

Would just need the javascript to calculate the "event.value" of the newly created field, let's call it "GP Course" for grade points, telling it to go "GRD Course" and convert the letter grade entered there to points (a numeric value).

Thanks for your assistance.
Jeff

View PostJMRKER, on 29 October 2013 - 07:46 PM, said:

See if you can modify this to your needs ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />

<title> Untitled </title>

</head>
<body>
<!--
I have set up fields for every course taken (ID Course),
 for credit hours attempted (HA Course),
 credit hours earned (HE Course),
 and letter grade (GRD Course) for all required classes
...
I have created a fourth field in the row for "Quality Points" (QP Course).
...
but I need to script that conversion into the calculation - multiply by hours earned (HE course)
-->

<input id="IDcourse" value="Course ID"> Course ID<br>
<input id="HAcourse" value=""> Hours attempted <br>
<input id="HEcourse" value=""> Hours earned<br>
<input id="GRDcourse" value=""> Grade (A..F)<br>
<input id="QPcourse" value="" readonly onclick="QPcalc()"> Quality Points<br>

<script type="text/javascript">
// For: http://www.dreamincode.net/forums/topic/332801-script-for-calculating-quality-points-from-units-and-letter-grade/

function $_(IDS) { return document.getElementById(IDS); };
function QPcalc() {
  var HE = Number($_('HEcourse').value);
  var GRD = $_('GRDcourse').value.toUpperCase();
  var QP;
  switch (GRD) {
    case 'A': QP = HE * 4; break;
    case 'B': QP = HE * 3; break;
    case 'C': QP = HE * 2; break;
    case 'D': QP = HE * 1; break;
    case 'F': QP = HE * 0; break;
     default: alert('Invalid Grade assignment'); QP = 0; break;
  }
  $_('QPcourse').value = QP;
}
window.onload = function() {
  $_('HAcourse').value = 20;
  $_('HEcourse').value = 15;
  $_('GRDcourse').value = 'A';
}
</script>

</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#4 headmasterofsoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-October 13

Re: script for calculating quality points from units and letter grade

Posted 30 October 2013 - 09:52 AM

Also for your reference, this is the custom script I entered into the field, that does nothing:

function $_(IDS) {return document.getElementById(IDS);}; function QPcalc() {var HE=Number($_('HE EH 101').value); var GRD=$_('GRD EH 101').value.toUpperCase(); var QP; switch (GRD) {case'A':QP=HE*4;break; case'B':QP=HE*3;break;case'C':QP=HE*2;break;case'D':QP=HE*1;break;case'F':QP=HE*0;break; default:alert('Invalid Grade Assignment');QP=0;break} $_('QP EH101').value=QP;} window.onload=function(){ $_('HA EH 101').value=20; $_('HE EH 101').value=15; $_('GRD EH 101').value='A';};


Do you think I need to change the term "Element" to get this field like in the previous script I sent that works?

Could it be the lack of spaces in certain spots, ot the lack of line breaks?

Jeff

View PostJMRKER, on 29 October 2013 - 07:46 PM, said:

See if you can modify this to your needs ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />

<title> Untitled </title>

</head>
<body>
<!--
I have set up fields for every course taken (ID Course),
 for credit hours attempted (HA Course),
 credit hours earned (HE Course),
 and letter grade (GRD Course) for all required classes
...
I have created a fourth field in the row for "Quality Points" (QP Course).
...
but I need to script that conversion into the calculation - multiply by hours earned (HE course)
-->

<input id="IDcourse" value="Course ID"> Course ID<br>
<input id="HAcourse" value=""> Hours attempted <br>
<input id="HEcourse" value=""> Hours earned<br>
<input id="GRDcourse" value=""> Grade (A..F)<br>
<input id="QPcourse" value="" readonly onclick="QPcalc()"> Quality Points<br>

<script type="text/javascript">
// For: http://www.dreamincode.net/forums/topic/332801-script-for-calculating-quality-points-from-units-and-letter-grade/

function $_(IDS) { return document.getElementById(IDS); };
function QPcalc() {
  var HE = Number($_('HEcourse').value);
  var GRD = $_('GRDcourse').value.toUpperCase();
  var QP;
  switch (GRD) {
    case 'A': QP = HE * 4; break;
    case 'B': QP = HE * 3; break;
    case 'C': QP = HE * 2; break;
    case 'D': QP = HE * 1; break;
    case 'F': QP = HE * 0; break;
     default: alert('Invalid Grade assignment'); QP = 0; break;
  }
  $_('QPcourse').value = QP;
}
window.onload = function() {
  $_('HAcourse').value = 20;
  $_('HEcourse').value = 15;
  $_('GRDcourse').value = 'A';
}
</script>

</body>
</html>


This post has been edited by laytonsdad: 30 October 2013 - 10:42 AM

Was This Post Helpful? 0
  • +
  • -

#5 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: script for calculating quality points from units and letter grade

Posted 30 October 2013 - 03:04 PM

View Postheadmasterofsoul, on 30 October 2013 - 10:45 AM, said:

Not working, nothing comes up - stays blank.
I think that fact I am working with a PDF application, Acrobat Pro 9 and not a web application, is going to make this script different. While not well versed in javascript, I do know about html code (I teach a web design course using Dreamweaver, make the student learn basic html code to troubleshoot).
I am also working with Apple Software, but I don't think that affected the fact it doesn't want to work.
Here is an example of the custom calculation script that does work, it does calculate the value for a field I created to calculating the overall GPA:


When you say that it is not working, do you mean with my stand-alone program or with the script embedded into the PDF?
The field will remain blank until you click on it. That is the event that starts the calculations to create the display.

I have no experience with using JS and Acrobat Pro 9 together.
Someone above by pay-grade might have more experience with this.
I do use an iMac at work and a PC at home. Both run my script fine.
Was This Post Helpful? 0
  • +
  • -

#6 headmasterofsoul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-October 13

Re: script for calculating quality points from units and letter grade

Posted 30 October 2013 - 06:43 PM

I think it is the Acrobat Pro that is asking for a custom calculation script.

I fear your javascript program was too complex, more than it will allow for. Right now I am looking for a more simple javascript that will take the letter grade entered and simply convert it to grade points...i.e. A=4, etc...in a different field. I am sure Acrobat will allow for that to happen, and then I will create a second extra field (the grade point value is the first) that will give me the Quality Points number.

In answer to your question, the script embedding into the area (that doesn't work) is looking to calculate a simple event.value
Clicking on it does nothing either. Can you help with the letter grade to grade points script?

Thanks, Jeff


When you say that it is not working, do you mean with my stand-alone program or with the script embedded into the PDF?
The field will remain blank until you click on it. That is the event that starts the calculations to create the display.

I have no experience with using JS and Acrobat Pro 9 together.
Someone above by pay-grade might have more experience with this.
I do use an iMac at work and a PC at home. Both run my script fine.
[/quote]
Was This Post Helpful? 0
  • +
  • -

#7 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: script for calculating quality points from units and letter grade

Posted 30 October 2013 - 08:30 PM

Hard to make it any simpler than this...
<script type="text/javascript">
function QPcalc(HE,GRD) {
  var QP = 0;
  switch (GRD) {
    case 'A': QP = HE * 4; break;
    case 'B': QP = HE * 3; break;
    case 'C': QP = HE * 2; break;
    case 'D': QP = HE * 1; break;
    case 'F': QP = HE * 0; break;
     default: alert('Invalid Grade assignment'); QP = 0; break;
  }
  return QP;
}

// Example function calls
alert(QPcalc('10','A'));  // result: 40
alert(QPcalc('10','B'));  // result: 30
alert(QPcalc('10','C'));  // result: 20
alert(QPcalc('10','D'));  // result: 10
alert(QPcalc('10','F'));  // result: 0

</script>


You can remove the default: logic line with the alert() message
if you are sure there is no parameter other than A,B,C,D,F (in upper case) passed to the function.

Without the Hours Earned (HE) value and calculations, the function would look like this:
<script type="text/javascript">
function QPconvert(GRD) {
  var QP;
  switch (GRD) {
    case 'A': QP = 4; break;
    case 'B': QP = 3; break;
    case 'C': QP = 2; break;
    case 'D': QP = 1; break;
    case 'F': QP =  0; break;
  }
  return QP;
}

alert(QPconvert('A'));  // result: 4
alert(QPconvert('B'));  // result: 3
alert(QPconvert('C'));  // result: 2
alert(QPconvert('D'));  // result: 1
alert(QPconvert('F'));  // result: 0

</script>



Finally, the shortest function I could come up with would look like this...
<script type="text/javascript">
function GRDconvert(GRD) { return 'FDCBA'.indexOf(GRD); }

alert(GRDconvert('A'));  // result: 4
alert(GRDconvert('B'));  // result: 3
alert(GRDconvert('C'));  // result: 2
alert(GRDconvert('D'));  // result: 1
alert(GRDconvert('F'));  // result: 0

</script>


This post has been edited by JMRKER: 31 October 2013 - 07:31 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1