/    Sign up×
Community /Pin to ProfileBookmark

Scholarship Score calculation

Hello, I am working voluntarily on a application form for a school in Iraq. The condition of filling this form is checking whether the applicant is eligible for scholarship program. This is based on couple conditional question which lead to final calculated score. I would like to do this JavaScript. Is there any chance that someone can put me in the right direction to do this please?

Here are the questions

This tool will allow you to calculate your scores for Scholarship

Where you at top of your school when you graduated: Yes [ ] No [ ]

What is your total Bsc score (ex, 65): [ ] {if yes and under 65 they get 25 score, if no and 65 they they get 25, but plus one score for any whole number over 65, a 66 gets 26, 67 gets 27 ..}

What are you applying for: MSc [ ] PhD [ ]

How many years of working experience do you have: [ ], if zero, please add 0

Is the study related to your working experience: Yes [ ] No [ ]

What type of offer do you have: Conditional [ ] Unconditional [ ]

What is your age: [ ], please round up/down to closest whole age, 25, 26, 27 …(between min 25- max 40)
A
{IF Msc and aged between min 25 (give 15 score) and max 35 (give 0 score), with 1 (1 year givae 2 score) to 5 (5 years give 10 score max) years experiences, related working experience gives 5 score, contional 5 score and uncondition 10 score}

What is your testing language [ ] and your score [ ]

Your total score for HCDP program is [ ]

to post a comment
JavaScript

29 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERDec 07.2010 — The following is [COLOR="Red"]NOT complete[/COLOR] because I don't understand some of your logic requirements.

See comments within code. ?

Give an attempt at fixing the logic using this as a starting point. ?
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt; Iraq Scholarship Application &lt;/title&gt;
&lt;script type="text/javascript"&gt;
// From: http://www.webdeveloper.com/forum/showthread.php?t=239477
// ONLY PARTIALLY COMPLETE AT THIS TIME! SEE LOGIC COMMENT BELOW.

function ComputeScore() {
var tmp = 0;
BScScore = Number(document.getElementById('BScScore').value);
var sum = 0;

// get Age
var Age = Number(document.getElementById('Age').value);
if ((Age &lt; 25) || (Age &gt; 40)) { alert('Not eligible due to age requirements'); return; }

/*
if "topOfClass" = yes and under "BSc" = 65 they get 25 score,
if no and 65 they they get 25, but plus one score for any whole number over 65, a 66 gets 26, 67 gets 27 ...
*/
if (getRBtnName('topOfClass') == "Y") {
sum += 25;
} else {
sum += 25;
if (BScScore &gt; 65) { sum += BScScore - 65; }
}

// add years of experience
var Exp = Number(document.getElementById('Experience').value);
sum += Exp;

/*
Following LOGIC is confusing to me ... Clarification is needed ... ???

IF Msc and aged between min 25 (give 15 score) and max 35 (give 0 score),
with 1 (1 year givae 2 score) to 5 (5 years give 10 score max) years experiences,
related working experience gives 5 score, contional 5 score and uncondition 10 score
*/
document.getElementById('TotalScore').value = sum.toFixed(0);
}

function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = '';
for (var i=0; i&lt;sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above <br/>
return str;
}

&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1 align="center"&gt; Iraq Scholarship Application &lt;/h1&gt;
&lt;h3&gt;This tool will allow you to calculate your scores for Scholarship&lt;/h3&gt;

&lt;table border="1"&gt;
&lt;tr&gt;
&lt;td align="right"&gt;
&lt;!-- What is the definition of "top"? Only one? Top 5? Top 10%? --&gt;
Where you at top of your school when you graduated:
&lt;/td&gt;&lt;td&gt;
&lt;input type="radio" name="topOfClass" value="Y"&gt; Yes
&lt;input type="radio" name="topOfClass" value="N"&gt; No
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
What is your total Bsc score (ex, 65):
&lt;/td&gt;&lt;td&gt;
&lt;input type="text" name="BScScore" id="BScScore" value="0"&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
What are you applying for:
&lt;/td&gt;&lt;td&gt;
&lt;input type="radio" name="MScApply" value="MSc"&gt; MSc
&lt;input type="radio" name="MScApply" value="PhD"&gt; PhD
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
How many years of working experience do you have:
&lt;/td&gt;&lt;td&gt;
&lt;input type="text" name="Experience" id="Experience" value="0"&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
Is the study related to your working experience:
&lt;/td&gt;&lt;td&gt;
&lt;input type="radio" name="Study" value="Y"&gt; Yes
&lt;input type="radio" name="Study" value="N"&gt; No
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
What type of offer do you have:
&lt;/td&gt;&lt;td&gt;
&lt;input type="radio" name="Offer" value="C"&gt; Conditional
&lt;input type="radio" name="Offer" value="U"&gt; Unconditional
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
What is your age:
&lt;br&gt; Age, please round up/down to closest whole age,
&lt;br&gt; 25, 26, 27 ...(between min 25- max 40)
&lt;/td&gt;&lt;td valign="top"&gt;
&lt;input type="text" name="Age" id="Age" value="0"&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
What is your testing language &lt;br&gt; and your score.
&lt;/td&gt;&lt;td&gt;
&lt;input type="text" name="testLanguage" value=""&gt;&lt;br&gt;
&lt;input type="text" name="LanguageScore" value=""&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;p&gt;
Your total score for HCDP program is
&lt;button onclick="ComputeScore()"&gt;Calculate&lt;/button&gt;
&lt;input type="text" name="TotalScore" id="TotalScore" value="" readonly&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@kirmashanauthorDec 08.2010 — Thank you very very much for taking your time and looking into this. Sorry my logic made you confused. Here is the link to the background of this score checking tool

https://docs.google.com/View?id=ddq9gs87_33dmxzbwf9
Copy linkTweet thisAlerts:
@JMRKERDec 08.2010 — Do you have an attempt to modify the script to your needs?
Copy linkTweet thisAlerts:
@kirmashanauthorDec 08.2010 — I will do my best, see if I can make it. What should be concerned when do this, as you have more understanding of the concept now?
Copy linkTweet thisAlerts:
@kirmashanauthorDec 17.2010 — I have been trying to make sense how I can get an auto sub value for each section and add them auto at the end,

here

http://drupal.kurdan.net/sites/all/themes/ministry/hcdp_score_10.html

But it does not work,
Copy linkTweet thisAlerts:
@JMRKERDec 17.2010 — Your calculation LOGIC is still confusing to me, so the last set of ComputerScore() function values are the same.

Therefore, as before, the [COLOR="Red"]following script is NOT complete[/COLOR] because I don't understand some of your logic requirements.

You should check the error console if using FF browser as you had a number of syntax errors.

I suggest you use 'id=...' in your elements to make it easier to reference (see changes below).

I cleaned up a lot of your code to make it 1) function and 2) be more readable.

Make sure you understand the changes provided before you go changing a lot of things.

In other words, make small changes and make sure they work to your satisfaction before you do a lot of changes that just leads to a mess of code.

Ask questions about specific code change rather than the general "it doesn't work" comment.

Note: No "onchange=..." events can occur on a "readonly" element.

Script is too long so I'll post in next section.
Copy linkTweet thisAlerts:
@JMRKERDec 17.2010 — Continued from previous post ...
<i>
</i>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt; HCDP Scholarship Application - Kurdistan region &lt;/title&gt;
&lt;script type="text/javascript"&gt;
// From:

function $_(IDS) { return document.getElementById(IDS); }

function addOption(IDS,Item,itemValue) {
var sel = $_(IDS);
sel.options[sel.options.length]=new Option(Item,itemValue,true,true);
}

function removeAllOptions(SelectBox) {
var sel = $_(SelectBox);
for (var i=sel.options.length-1; i&gt;=0; i--) { sel.remove(i); }
}

var TestLanguageList = ['PASSWORD','IELTS','TOEFL ITP','TOEFL COMPUTER','TOEFL IBT','TOEFL PAPER'];
var PasswordList = ['PP','6.0','5.5','5.0','4.5','4.0','3.5','3.0'];
var IELTSList = ['6.0','5.5','5.0','4.5','4.0','3.5','3.0','2.5'];
var TOEFLitpList = ['575','550','525','500','475','450','425','400'];
var TOEFLcomputerList = ['213','190','173','152','133','113','93','75'];
var TOEFLibtList = ['80','70','60','50','40','30','20','10'];
var TOEFLpaperList = ['550','525','500','475','450','425','400','375'];

function FillTestLanguage() {
// this function is used to fill the Testing Language list on load
for (var i=0; i&lt;TestLanguageList.length; i++) {
addOption('TestLanguage',TestLanguageList[i],TestLanguageList[i]);
}
$_('TestLanguage').selectedIndex = 0;
}

function SelectYourScore() {
// ON selection of category this function will work
removeAllOptions('YourScore');
addOption('YourScore', "YourScore", "");

switch ($_('TestLanguage').value) {
case 'PASSWORD' :
for (var i=0; i&lt;PasswordList.length; i++) {
addOption('YourScore',PasswordList[i],PasswordList[i]);
} break;
case 'IELTS' :
for (var i=0; i&lt;IELTSList.length; i++) {
addOption('YourScore',IELTSList[i],IELTSList[i]);
} break;
case 'TOEFL ITP' :
for (var i=0; i&lt;TOEFLitpList.length; i++) {
addOption('YourScore',TOEFLitpList[i],TOEFLitpList[i]);
} break;
case 'TOEFL COMPUTER' :
for (var i=0; i&lt;TOEFLcomputerList.length; i++) {
addOption('YourScore',TOEFLcomputerList[i],TOEFLcomputerList[i]);
} break;
case "TOEFL IBT" :
for (var i=0; i&lt;TOEFLibtList.length; i++) {
addOption('YourScore',TOEFLibtList[i],TOEFLibtList[i]);
} break;
case "TOEFL PAPER" :
for (var i=0; i&lt;TOEFLpaperList.length; i++) {
addOption('YourScore',TOEFLpaperList[i],TOEFLpaperList[i]);
} break;
default : alert('Invalid selection'); break;
}
$_('YourScore').selectedIndex = 0;
}

var MScAgeList = ['25','26','27','28','29','30','31','32','33','34','35'];
var PhDAgeList = ['30','31','32','33','34','35','36','37','38','39','40'];

function populate_dropdown(setAge) {
removeAllOptions('your_Age');
switch(setAge) {
case "MSc":
for (var i=0; i&lt;MScAgeList.length; i++) {
addOption('your_Age',MScAgeList[i],MScAgeList[i]);
} break;
case "PhD":
for (var i=0; i&lt;PhDAgeList.length; i++) {
addOption('your_Age',PhDAgeList[i],PhDAgeList[i]);
} break;
default:
addOption('your_Age','Select MSc or PhD first', "");
break;
}
$_('your_Age').selectedIndex = 0;
}

// From: http://www.webdeveloper.com/forum/showthread.php?t=239477
// ONLY PARTIALLY COMPLETE AT THIS TIME! SEE LOGIC COMMENT BELOW.

function ComputeScore() {
var tmp = 0;
bscScore = Number(document.getElementById('BScScore').value); if (isNaN(bscScore)) { bscScore = 0; }
var sum = 0;

// get Age
var Age = Number(document.getElementById('your_Age').value);
if ((Age &lt; 25) || (Age &gt; 40)) { alert('Not eligible due to age requirements'); return; }
$_('Score10').value = sum;

/*
if "topOfClass" = yes and under "BSc" = 65 they get 25 score,
if no and 65 then they get 25, but plus one score for any whole number over 65, a 66 gets 26, 67 gets 27 ...
*/
if (getRBtnName('topOfClass') == "Y") {
sum += 25;
} else {
if (bscScore &gt;= 65) { sum += 25; }
if (bscScore &gt; 65) { sum += bscScore - 65; }
}
$_('Score20').value = sum;

// add years of experience
var Exp = Number(document.getElementById('Experience').value); if (isNaN(Exp)) { Exp = 0; }
sum += Exp;
$_('Score30').value = sum;

/*
Following LOGIC is confusing to me ... Clarification is needed ... ???

IF Msc and aged between min 25 (give 15 score) and max 35 (give 0 score),
with 1 (1 year givae 2 score) to 5 (5 years give 10 score max) years experiences,
related working experience gives 5 score, contional 5 score and uncondition 10 score
*/

$_('Score40').value = sum;
$_('Score50').value = sum;
$_('Score60').value = sum;

/* No changes to score as LOGIC is confusing to me ... Clarification is needed ... ??? */

document.getElementById('TotalScore').value = sum.toFixed(0);
}

function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = '';
for (var i=0; i&lt;sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above <br/>
return str;
}

&lt;/script&gt;
&lt;/head&gt;

&lt;body onLoad="FillTestLanguage();"&gt;

&lt;h1 align="center"&gt;HCDP Scholarship Application&lt;/h1&gt;

&lt;h3&gt;This tool will allow you to calculate your scores for Scholarship&lt;/h3&gt;

&lt;form action="HCDP_Scores" method="post" onsubmit="return false"&gt;

&lt;table border="1"&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
&lt;!-- What is the definition of "top"? Only one? Top 5? Top 10%? --&gt;
Where you at top of your school when you graduated:
&lt;/td&gt;
&lt;td&gt;
&lt;input type="radio" name="topOfClass" value="Y"&gt; Yes
&lt;input type="radio" name="topOfClass" value="N"&gt; No
&lt;/td&gt;
&lt;td valign="top"&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What is your total Bsc score (ex, 65): &lt;/td&gt;
&lt;td&gt; &lt;input type="text" name="BScScore" id="BScScore" value="0"&gt; &lt;/td&gt;
&lt;td valign="top"&gt;
&lt;!-- CANNOT EVER DO ANYTHING IF INPUT IS SET TO readonly !!! and calculate() is not defined --&gt;
&lt;input type="text" id="Score10" name="Score10" size="12" tabindex="10" onChange="calculate()" readonly&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What are you applying for: &lt;/td&gt;
&lt;td&gt;
&lt;input id="MSc" type="radio" name="setAge" value="MSc" onClick="populate_dropdown('MSc')" /&gt;&lt;label for="MSc"&gt;MSc&lt;/label&gt;
&lt;input id="PhD" type="radio" name="setAge" value="PhD" onClick="populate_dropdown('PhD')" /&gt;&lt;label for="PhD"&gt;PhD&lt;/label&gt;
&lt;/td&gt;
&lt;td valign="top"&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What is your age:
&lt;br&gt; Age, please round up/down to closest whole age,
&lt;br&gt; 25, 26, 27 ...(between min 25- max 40)
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;select id="your_Age" name="your_Age"&gt;
&lt;option&gt;Select MSc/PhD first&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;!-- CANNOT EVER DO ANYTHING IF INPUT IS SET TO readonly !!! and calculate() is not defined --&gt;
&lt;input type="text" id="Score20" name="Score20" size="12" tabindex="20" onChange="calculate()" readonly&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; How many years of working experience do you have: &lt;/td&gt;
&lt;td&gt;
&lt;select id="Experience" name="Experience" size="1"&gt;
&lt;option value="0"&gt;0&lt;/option&gt; &lt;option value="1"&gt;1&lt;/option&gt;
&lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="3"&gt;3&lt;/option&gt;
&lt;option value="4"&gt;4&lt;/option&gt; &lt;option value="5"&gt;5&lt;/option&gt;
&lt;option value="6"&gt;6&lt;/option&gt; &lt;option value="7"&gt;7&lt;/option&gt;
&lt;option value="8"&gt;8&lt;/option&gt; &lt;option value="9"&gt;9&lt;/option&gt;
&lt;option value="10"&gt;10&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;!-- CANNOT EVER DO ANYTHING IF INPUT IS SET TO readonly !!! and calculate() is not defined --&gt;
&lt;input type="text" id="Score30" name="Score30" size="12" tabindex="30" onChange="calculate()" readonly&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; Is the study related to your working experience: &lt;/td&gt;
&lt;td&gt;
&lt;input type="radio" name="Study" value="Y"&gt; Yes
&lt;input type="radio" name="Study" value="N"&gt; No
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;!-- CANNOT EVER DO ANYTHING IF INPUT IS SET TO readonly !!! and calculate() is not defined --&gt;
&lt;input type="text" id="Score40" name="Score40" size="12" tabindex="40" onChange="calculate()" readonly&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What type of offer do you have: &lt;/td&gt;
&lt;td&gt;
&lt;input type="radio" name="Offer" value="C"&gt; Conditional
&lt;input type="radio" name="Offer" value="U"&gt; Unconditional
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;!-- CANNOT EVER DO ANYTHING IF INPUT IS SET TO readonly !!! and calculate() is not defined --&gt;
&lt;input type="text" id="Score50" name="Score50" size="12" tabindex="50" onChange="calculate()" readonly&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What is your testing language &lt;br&gt; and your score. &lt;/td&gt;
&lt;td&gt;
&lt;SELECT id="TestLanguage" NAME="TestLanguage" onChange="SelectYourScore();" &gt;
&lt;Option value=""&gt;Testing Language&lt;/option&gt;
&lt;/SELECT&gt;&amp;nbsp;
&lt;SELECT id="YourScore" NAME="YourScore"&gt; &lt;Option value=""&gt;Your Score&lt;/option&gt; &lt;/SELECT&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;!-- CANNOT EVER DO ANYTHING IF INPUT IS SET TO readonly !!! and calculate() is not defined --&gt;
&lt;input type="text" id="Score60" name="Score60" size="12" tabindex="60" onChange="calculate()" readonly&gt;
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt; Your total score for HCDP program is: &lt;/td&gt;
&lt;td&gt; &lt;button onclick="ComputeScore()"&gt;Calculate&lt;/button&gt; &lt;/td&gt;
&lt;td&gt; &lt;input type="text" name="TotalScore" id="TotalScore" size="15" tabindex="100" readonly&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@kirmashanauthorDec 18.2010 — Many thanks I will follow you instruction, As for readonly I was looking at this page

http://www.htmlgoodies.com/legacy/beyond/webmaster/projects/3withcotf3.html

Where the result of each selection shown at the selected stage and then added to the final result. I thought this can be helpful if applicant can see what they get at different stages which will build up the final results. These stages are independent.

The TOP definition is not important (they will be asked to provide a document to prove that they were among the TOP student when they graduated), we need the value of YES or NO to make someone with a BSC grade less than 65 eligible to apply. This is only important is BSC is under 65.

Let say, I have a BSC grade of 61 and I select YES to the question about the TOP student. Then will give me 25 Score at this stage.

Then I go to next stage as shown here

http://drupal.kurdan.net/sites/all/themes/ministry/hcdp_score_11.html

But the logic is explained here as well

https://docs.google.com/View?id=ddq9gs87_33dmxzbwf9
Copy linkTweet thisAlerts:
@kirmashanauthorDec 18.2010 — @JMRKER,

Can I get the value of a check Radio button or dropdown and display it as a result of a section such as

<SCRIPT language="JavaScript">

// return the value of the radio button that is checked

// return an empty string if none are checked, or

// there are no radio buttons

function getCheckedValue(Study) {

if(!Study)

return "";

var radioLength = Study.length;

if(radioLength == undefined)

if(Study.checked)

return Study.value;

else

return "";

for(var i = 0; i < radioLength; i++) {

if(Study[i].checked) {

return Study[i].value;

}

}

return "";

}

</SCRIPT>



<FORM name="myform">



<input type="radio" name="Study" value="5"> Yes

<input type="radio" name="Study" value="0"> No



<input type="text" id="Score40" name="Score40" size="12" tabindex="40" onChange="getCheckedValue()">



</FORM>
Copy linkTweet thisAlerts:
@JMRKERDec 18.2010 — It's already coded for you.

Look at the function 'getRBtnName(GrpName)' and use:
<i>
</i> var studyInfo = getRBtnName('Study');

That returns the value checked from the radio button.

If nothing is checked, it returns a '' (blank) string.
Copy linkTweet thisAlerts:
@kirmashanauthorDec 18.2010 — ? I did missed that, however, I managed to get the value for stage 3, 4, and 5 and auto add them as you can see here

http://drupal.kurdan.net/sites/all/themes/ministry/hcdp_score_11.html

But the remaining stages are more complex do you think you can help me with these cases please.
Copy linkTweet thisAlerts:
@JMRKERDec 18.2010 — As I said in the original post:

/*

Following LOGIC is confusing to me ... Clarification is needed ... ???

IF Msc and aged between min 25 (give 15 score) and max 35 (give 0 score),

with 1 (1 year givae 2 score) to 5 (5 years give 10 score max) years experiences,

related working experience gives 5 score, contional 5 score and uncondition 10 score

*/
[/quote]

I don't mind helping, but I need specifics.

?

What scores are not working correctly?

What is the logic involved in creating the specific score?

Can you provide examples of input conditions and expected outputs?

The logic of your program confuses me.

State your problem one step at a time.

BTW: Why are you till using event clicks to create the totals

instead of using the "Calculate" button?


If you try to do the calculations on the fly, you get "undefined" errors because all the information is not available for the calculations to be completed!

:eek:
Copy linkTweet thisAlerts:
@kirmashanauthorDec 18.2010 — Many thanks, We are planing to announce the new round of scholarship next week.

As you can see on the page, Score for step 1, 2, and 6 are not working.

You logic for step 1 (Score10 field) is correct and when you click on calcs, correct value is displayed. so this just need to appear on fly like 3,4,and 5,

After reading this, is it still unclear how the logic works?

https://docs.google.com/View?id=ddq9gs87_33dmxzbwf9

What is the logic involved in creating the specific score?

So the applicant can see what score they have for each section and how they are put together as explained in the document above.

Can you provide examples of input conditions and expected outputs?

[1] Applicant with BSc grade of 68,

[2] 27 yeas old applying for MSc program,

[3] with 4 years experience

[4] which is related to the study,

[5] An unconditional offer placement,

[6] With TOFEL COMPUTER result of 133

At step one gets : 25+(68-65)=28 (field score10)

At step two gets : 12 (field score20, based on the table in the link document above)

At step three gets : 8 (field score30) this works already

At step four gets : 5 (field score40) this works already

At step five gets : 10 (field score50) this works already

At step SIX gets : 6 (field score60) this does not work

The sum will be 69 Scores

This will provide the applicant enough information whether they should fill the form and apply.

State your problem one step at a time.

The problem remains in Step 1, 2, and 6 now,

Step 1 provide the results correctly but I want it the same way as 3, 4, and 5 (on fly)

Step 2, each select age from dropdown should corresponds to a value displayed on fly in field Score20. These values are in the table in the linked document

Step 6, the problem is the same as step 2.


Why are you till using event clicks to create the totals instead of using the "Calculate" button?

I want this to happen as soon applicant make selection and enter data. Is there any way to make the Score field default value 0 which can be over written when selection is made?
Copy linkTweet thisAlerts:
@JMRKERDec 19.2010 — Try this:
<i>
</i>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt; HCDP Scholarship Application - Kurdistan region &lt;/title&gt;
&lt;script type="text/javascript"&gt;
// From: http://www.webdeveloper.com/forum/showthread.php?p=1130042#post1130042

function $_(IDS) { return document.getElementById(IDS); }

function addOption(IDS,Item,itemValue) {
var sel = $_(IDS);
sel.options[sel.options.length]=new Option(Item,itemValue,true,true);
}

function removeAllOptions(SelectBox) {
var sel = $_(SelectBox);
for (var i=sel.options.length-1; i&gt;=0; i--) { sel.remove(i); }
}

var TestLanguageList = ['PASSWORD','IELTS','TOEFL ITP','TOEFL COMPUTER','TOEFL IBT','TOEFL PAPER'];
var PasswordList = ['PP:10','6.0:10','5.5:8','5.0:8','4.5:6','4.0:6','3.5:4','3.0:4'];
var IELTSList = ['6.0:10','5.5:10','5.0:8','4.5:8','4.0:6','3.5:6','3.0:4','2.5:4'];
var TOEFLitpList = ['575:10','550:10','525:8','500:8','475:6','450:6','425:4','400:4'];
var TOEFLcomputerList = ['213:10','190:10','173:8','152:8','133:6','113:6','93:4','75:4'];
var TOEFLibtList = ['80:10','70:10','60:8','50:8','40:6','30:6','20:4','10:4'];
var TOEFLpaperList = ['550:10','525:10','500:8','475:8','450:6','425:6','400:4','375:4'];

function FillTestLanguage() {
for (var i=0; i&lt;TestLanguageList.length; i++) {
addOption('TestLanguage',TestLanguageList[i],TestLanguageList[i]);
} $_('TestLanguage').selectedIndex = 0;
}

function SelectYourScore() {
removeAllOptions('YourScore');
addOption('YourScore', "YourScore", "");
var tarr = [];
switch ($_('TestLanguage').value) {
case 'PASSWORD' :
for (var i=0; i&lt;PasswordList.length; i++) {
tarr = PasswordList[i].split(':'); addOption('YourScore',tarr[0],tarr[1]);
} break;
case 'IELTS' :
for (var i=0; i&lt;IELTSList.length; i++) {
tarr = IELTSList[i].split(':'); addOption('YourScore',tarr[0],tarr[1]);
} break;
case 'TOEFL ITP' :
for (var i=0; i&lt;TOEFLitpList.length; i++) {
tarr = TOEFLitpList[i].split(':'); addOption('YourScore',tarr[0],tarr[1]);
} break;
case 'TOEFL COMPUTER' :
for (var i=0; i&lt;TOEFLcomputerList.length; i++) {
tarr = TOEFLcomputerList[i].split(':'); addOption('YourScore',tarr[0],tarr[1]);
} break;
case "TOEFL IBT" :
for (var i=0; i&lt;TOEFLibtList.length; i++) {
tarr = TOEFLibtList[i].split(':'); addOption('YourScore',tarr[0],tarr[1]);
} break;
case "TOEFL PAPER" :
for (var i=0; i&lt;TOEFLpaperList.length; i++) {
tarr = TOEFLpaperList[i].split(':'); addOption('YourScore',tarr[0],tarr[1]);
} break;
default : alert('Invalid selection'); break;
}
$_('YourScore').selectedIndex = 0;
}

var MScAgeList = ['25','26', '27','28', '29','30', '31','32', '33','34', '35'];
var PhDAgeList = ['30','31', '32','33', '34','35', '36','37', '38','39', '40'];
var AgePoints = ['15','13.5','12','10.5', '9', '7.5','6', '4.5','4', '1.5','0'];

function populate_dropdown(setAge) {
removeAllOptions('your_Age');
switch(setAge) {
case "MSc":
for (var i=0; i&lt;MScAgeList.length; i++) {
addOption('your_Age',MScAgeList[i],MScAgeList[i]);
} break;
case "PhD":
for (var i=0; i&lt;PhDAgeList.length; i++) {
addOption('your_Age',PhDAgeList[i],PhDAgeList[i]);
} break;
default:
addOption('your_Age','Select MSc or PhD first', "");
break;
} $_('your_Age').selectedIndex = 0;
}

function ComputeScore() {
var tmp = 0;
bscScore = Number($_('BScScore').value); if (isNaN(bscScore)) { bscScore = 0; }
var sum = 0;

// get Age
var Age = Number($_('your_Age').value);
if ((Age &lt; 25) || (Age &gt; 40)) { alert('Not eligible due to age requirements'); return; }

// Stage 1 calculations: determine start score base on TOC or BSc score
if (getRBtnName('topOfClass') == "Y") { sum = 25; } // top of class get score of 25 only
if (bscScore &gt;= 65) { sum = 25 + bscScore - 65; } // not top of class but score 65 or over
// else { alert('Not eligible for scholarship'); return }
$_('Score10').value = sum;

// Stage 2 calculations: MSc or PhD and age modifications
sum += Number(AgePoints[$_('your_Age').selectedIndex]); <br/>
$_('Score20').value = sum;

// Stage 3 calculations: add work experience
var Exp = Number($_('myExperience').value); <br/>
if (isNaN(Exp)) { Exp = 0; }
sum += Exp;
$_('Score30').value = sum;

// Stage 4 calculations: Study related to experience = +5 points;
tmp = Number(getRBtnName('myStudy')); if (isNaN(tmp)) { tmp = 0; }
sum += tmp;
$_('Score40').value = sum;

// Stage 5 calculations: Conditional vs Unconditional acceptance
tmp = Number(getRBtnName('myOffer')); if (isNaN(tmp)) { tmp = 0; }
sum += tmp;
$_('Score50').value = sum;

// Stage 6 calculations: Language skills adjustment
tmp = Number($_('YourScore').value); if (isNaN(tmp)) { tmp = 0; }
sum += tmp;
$_('Score60').value = sum;

$_('TotalScore').value = sum.toFixed(0);
}

function getRBtnName(GrpName) {
var sel = document.getElementsByName(GrpName);
var fnd = -1;
var str = '';
for (var i=0; i&lt;sel.length; i++) {
if (sel[i].checked == true) { str = sel[i].value; fnd = i; }
}
// return fnd; // return option index of selection
// comment out next line if option index used in line above <br/>
return str;
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body onLoad="FillTestLanguage();"&gt;
&lt;h1 align="center"&gt;HCDP Scholarship Application&lt;/h1&gt;
&lt;h3&gt;This tool will allow you to calculate your scores for Scholarship&lt;/h3&gt;
&lt;form name="HCDP_Form" action="HCDP_Scores" method="post" onsubmit="return false"&gt;

&lt;table border="1"&gt;

&lt;tr&gt;
&lt;td align="right"&gt;
Where you at top of your school when you graduated:
&lt;/td&gt;
&lt;td&gt;
&lt;input type="radio" name="topOfClass" value="Y" onclick="ComputeScore()"&gt; Yes
&lt;input type="radio" name="topOfClass" value="N" onclick="ComputeScore()" checked&gt; No
&lt;/td&gt;
&lt;td valign="top"&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What is your total Bsc score (ex, 65): &lt;/td&gt;
&lt;td&gt; &lt;input type="text" name="BScScore" id="BScScore" value="0" onblur="ComputeScore()"&gt; &lt;/td&gt;
&lt;td valign="top"&gt;
&lt;input type="text" id="Score10" name="Score10" size="6" tabindex="10" readonly&gt; Stage 1
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What are you applying for: &lt;/td&gt;
&lt;td&gt;
&lt;label&gt;
&lt;input id="MSc" type="radio" name="setAge" value="MSc" onClick="populate_dropdown('MSc')" /&gt; MSc
&lt;/label&gt;
&lt;label&gt;
&lt;input id="PhD" type="radio" name="setAge" value="PhD" onClick="populate_dropdown('PhD')" /&gt; PhD
&lt;/label&gt;
&lt;/td&gt;
&lt;td valign="top"&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What is your age?
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;select id="your_Age" name="your_Age" onchange="ComputeScore()"&gt;
&lt;option&gt;Select MSc/PhD first&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;input type="text" id="Score20" name="Score20" size="6" tabindex="20" readonly&gt; Stage 2
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; How many years of working experience do you have: &lt;/td&gt;
&lt;td&gt;
&lt;select id="myExperience" name="myExperience" size="1" onchange="ComputeScore()"&gt;
&lt;option value="0" selected&gt;0&lt;/option&gt;
&lt;option value="2"&gt;1&lt;/option&gt; &lt;option value="4"&gt;2&lt;/option&gt;
&lt;option value="6"&gt;3&lt;/option&gt; &lt;option value="8"&gt;4&lt;/option&gt;
&lt;option value="10"&gt;5&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;input type="text" id="Score30" name="Score30" size="6" tabindex="30" readonly&gt; Stage 3
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; Is the study related to your working experience: &lt;/td&gt;
&lt;td&gt;
&lt;span onclick="ComputeScore()"&gt;
&lt;label&gt; &lt;input type="radio" name="myStudy" value="5"&gt; YES &lt;/label&gt;
&lt;label&gt; &lt;input type="radio" name="myStudy" value="0"&gt; NO &lt;/label&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;input type="text" tabindex="40" id="Score40" name="Score40" size="6" readonly&gt; Stage 4
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What type of offer do you have: &lt;/td&gt;
&lt;td&gt;
&lt;span onClick='ComputeScore()'&gt;
&lt;label&gt; &lt;input type="radio" name="myOffer" value="0" checked&gt; None &lt;/label&gt;
&lt;label&gt; &lt;input type="radio" name="myOffer" value="5"&gt; Conditional &lt;/label&gt;
&lt;label&gt; &lt;input type="radio" name="myOffer" value="10"&gt; Unconditional &lt;/label&gt;
&lt;/span&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;input type="text" id="Score50" name="Score50" size="6" tabindex="50" readonly&gt; Stage 5
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align="right"&gt; What is your testing language and your score. &lt;/td&gt;
&lt;td&gt;
&lt;SELECT id="TestLanguage" NAME="TestLanguage" onChange="SelectYourScore();" &gt;
&lt;Option value=""&gt;Testing Language&lt;/option&gt;
&lt;/SELECT&gt;&amp;nbsp;
&lt;SELECT id="YourScore" NAME="YourScore" onchange="ComputeScore()"&gt;
&lt;Option value=""&gt;Your Score&lt;/option&gt;
&lt;/SELECT&gt;
&lt;/td&gt;
&lt;td valign="top"&gt;
&lt;input type="text" id="Score60" name="Score60" size="6" tabindex="60" readonly&gt; Stage 6
&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt; Your total score for HCDP program is: &lt;/td&gt;
&lt;td valign="top"&gt; &lt;button onclick="ComputeScore()"&gt;Calculate&lt;/button&gt; &lt;/td&gt;
&lt;td&gt; &lt;input type="text" name="TotalScore" id="TotalScore" size="15" tabindex="100" readonly&gt;
&lt;/tr&gt;

&lt;/table&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@kirmashanauthorDec 19.2010 — This is great,

I have uploaded here

http://drupal.kurdan.net/sites/all/themes/ministry/hcdp_score_12.html

I think it needs to represent scores for each stage independently and then show the add at the final Grand Total. At the moment it add them all the way. An applicant need to see what they get at each stage.
Copy linkTweet thisAlerts:
@kirmashanauthorDec 19.2010 — I do not know how I can change this bit, but this section should SUM but show the value for that stage only, and then in the last field TOTAL add them up

PS: it should be a case where applicant is TOP OF THE CLASS and have Score 65 or plus where the TOP OF the class selection should be ignored. It is important only if the person has BSc score less than 65.

$_('Score10').value = sum;

// Stage 2 calculations: MSc or PhD and age modifications

sum += Number(AgePoints[$_('your_Age').selectedIndex]);


$_
('Score20').value = sum;

// Stage 3 calculations: add work experience

var Exp = Number($_('myExperience').value);


if (isNaN(Exp)) { Exp = 0; }

sum += Exp;

$_
('Score30').value = sum;

// Stage 4 calculations: Study related to experience = +5 points;

tmp = Number(getRBtnName('myStudy')); if (isNaN(tmp)) { tmp = 0; }

sum += tmp;

$_('Score40').value = sum;

// Stage 5 calculations: Conditional vs Unconditional acceptance

tmp = Number(getRBtnName('myOffer')); if (isNaN(tmp)) { tmp = 0; }

sum += tmp;

$_('Score50').value = sum;

// Stage 6 calculations: Language skills adjustment

tmp = Number($_('YourScore').value); if (isNaN(tmp)) { tmp = 0; }

sum += tmp;

$_
('Score60').value = sum;

$_('TotalScore').value = sum.toFixed(0);

}
Copy linkTweet thisAlerts:
@JMRKERDec 19.2010 — For each stage you want a calculation, save the information to a temporary variable.
<i>
</i>// Stage 3 calculations: add work experience
tmp = Number($_('myExperience').value); if (isNaN(tmp)) { tmp = 0; }
sum += tmp;
$_('Score30').value = tmp;

// Stage 4 calculations: Study related to experience = +5 points;
tmp = Number(getRBtnName('myStudy')); if (isNaN(tmp)) { tmp = 0; }
sum += tmp;
$_('Score40').value = tmp;

// Stage 5 calculations: Conditional vs Unconditional acceptance
tmp = Number(getRBtnName('myOffer')); if (isNaN(tmp)) { tmp = 0; }
sum += tmp;
$_('Score50').value = tmp;

// Stage 6 calculations: Language skills adjustment
tmp = Number($_('YourScore').value); if (isNaN(tmp)) { tmp = 0; }
sum += tmp;
$_('Score60').value = tmp;

$_('TotalScore').value = sum.toFixed(0);
}

BTW: Do you have any experience with javascript other that cut-and-paste?
Copy linkTweet thisAlerts:
@kirmashanauthorDec 20.2010 — no I do not have any experience, This my first attempt. I can read the code and what it suppose to do. I do not consider myself a programmer but love to learn

This is perfect

http://drupal.kurdan.net/sites/all/themes/ministry/hcdp_score_13.html

Still adds Stage one and two together

Do we still need calc button? can I remove it.
Copy linkTweet thisAlerts:
@JMRKERDec 20.2010 — no I do not have any experience, This my first attempt. I can read the code and what it suppose to do. I do not consider myself a programmer but love to learn

This is perfect

http://drupal.kurdan.net/sites/all/themes/ministry/hcdp_score_13.html

Still adds Stage one and two together

Do we still need calc button? can I remove it.[/QUOTE]


You may have bitten off more that you should for a first time experience,

so to get some experience, try modifying the code for your Stage 1 & 2 displays yourself. Show your work and test it out for accuracy.

No, the calc button is not needed, and yes you can remove it.

It would be better to hide it with comment tags just incase you want to put it back in later!
Copy linkTweet thisAlerts:
@kirmashanauthorDec 20.2010 — Many many thanks for your help, I will do my best to make that modification.
Copy linkTweet thisAlerts:
@kirmashanauthorDec 20.2010 — I managed to make those changes and this is the final version

http://drupal.kurdan.net/sites/all/themes/ministry/hcdp_score_14.html

Thank you, this would have been possible without your help.
Copy linkTweet thisAlerts:
@JMRKERDec 20.2010 — You're most welcome.

Glad to have been of some help.

Would suggest you continue your experience and work through some on-line JS tutorials

Good Luck!

BTW: Looks like you get to have 15 points with an age of 0 before selecting MSc or PhD

But it's a minor problem that becomes resolved when user selects proper settings.
Copy linkTweet thisAlerts:
@kirmashanauthorDec 21.2010 — ? I see, I did not notice that, It sounds that I need a precondition before this section executed. I think it picks up the first value of AgePoints before any selection.

var MScAgeList = ['25','26', '27','28', '29','30', '31','32', '33','34', '35'];

var PhDAgeList = ['30','31', '32','33', '34','35', '36','37', '38','39', '40'];

var AgePoints = ['15','13.5','12','10.5', '9', '7.5','6', '4.5','4', '1.5','0'];

function populate_dropdown(setAge) {

removeAllOptions('your_Age');

switch(setAge) {

case "MSc":

for (var i=0; i<MScAgeList.length; i++) {

addOption('your_Age',MScAgeList[i],MScAgeList[i]);

} break;

case "PhD":

for (var i=0; i<PhDAgeList.length; i++) {

addOption('your_Age',PhDAgeList[i],PhDAgeList[i]);

} break;

default:

addOption('your_Age','Select MSc or PhD first', "");

break;

} $_('your_Age').selectedIndex = 0;

}
Copy linkTweet thisAlerts:
@JMRKERDec 21.2010 — You're on the right track.

Other possibility is to add at '' as an initial value for the three arrays.

You might need to adjust the <select...> for an initial condition display like: "Select Age"

Or leave the arrays alone and check for selectIndex < 0 when no radio button has been chosen.

You should pick the one that works best for what you are trying to do.
Copy linkTweet thisAlerts:
@kirmashanauthorDec 21.2010 — I did try this, but it does not work

function populate_dropdown(setAge) {

IF (document.HCDP_Form.setAge[0].checked)

removeAllOptions('your_Age');

switch(setAge) {

case "MSc":

for (var i=0; i<MScAgeList.length; i++) {

addOption('your_Age',MScAgeList[i],MScAgeList[i]);

} break;

case "PhD":

for (var i=0; i<PhDAgeList.length; i++) {

addOption('your_Age',PhDAgeList[i],PhDAgeList[i]);

} break;

default:

addOption('your_Age','Select MSc or PhD first', "");

break;

} $_('your_Age').selectedIndex = 0;

}
Copy linkTweet thisAlerts:
@JMRKERDec 21.2010 — [COLOR="Red"][SIZE="4"]This is untested, see if it works for you:[/SIZE][/COLOR]
<i>
</i> var MScAgeList = ['0','25','26', '27','28', '29','30', '31','32', '33','34', '35'];
var PhDAgeList = ['0','30','31', '32','33', '34','35', '36','37', '38','39', '40'];
var AgePoints = ['0','15','13.5','12','10.5', '9', '7.5','6', '4.5','4', '1.5','0'];

function populate_dropdown(setAge) {
removeAllOptions('your_Age');
switch(setAge) {
case "MSc":
addOption('your_Age','Choose your age:', "");
for (var i=1; i&lt;MScAgeList.length; i++) {
addOption('your_Age',MScAgeList[i],MScAgeList[i]);
} break;
case "PhD":
addOption('your_Age','Choose your age:', "");
for (var i=1; i&lt;PhDAgeList.length; i++) {
addOption('your_Age',PhDAgeList[i],PhDAgeList[i]);
} break;
default:
addOption('your_Age','Select MSc or PhD first', "");
break;
} $_('your_Age').selectedIndex = 0;
}


Note: Your attempt does not do what you want as you have no condition after the if (which should be in lowercase anyway).

At best, all it would do is "removeAllOption('your_Age')", which it does anyway.

At worst, it would bypass the removal of the previous options.

There is no reason to go back to DOM control of actions when you have the getElementById() function used ever where else.
Copy linkTweet thisAlerts:
@JMRKERDec 21.2010 — Looks good.

Good Luck!

?


Note: Restart this calculator button doesn't. Consider looking into reset().
Copy linkTweet thisAlerts:
@kirmashanauthorDec 30.2010 — The restart just put the history() to zero , I will tray reset() then
×

Success!

Help @kirmashan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...