Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

School fee calculator for parents 1

Status
Not open for further replies.

pulsarkuant

IS-IT--Management
Apr 7, 2009
74
0
0
TR
Hi,

I would like to create a calculator which can help parents when they calculate their student's school fees on our school's joomla web site. Ive attached our school's fee table. Is there anyone who can help me please?

Regards
 
This is not a coding site. If in the course of development problems arise, we can take a look at your code and help out.

What have you tried so far? Seems the first thing to do would be to build a form, if any input is required. Looking a the table I would suggest a drop down that has the grades with their costs. If more than one child can be added you can have buttons to allow this.

The discount can be applied once all children have been added.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi,

I found a code but couldnt make it run. It doesnt give me the results.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Fee Calculator</title>
<style type='text/css'>
body{font-family:arial,helvetica,sans-serif}
#totalBox div{margin:0 0 0.5em 0}
div{margin-top:1em}
input[type=radio]{margin:0.5em 0.5em 0.5em 1em}
.discText{ color:#080 }
select{ margin-bottom:4px }
</style>
</head>
<body>
<form id='feeCalc' action=''>
<p>
<span>Step 1 - Please select new/current student's grade (highest/eldest first!)</span><p>
<select name='academicYear' style='display:block'>
<option> Select Grade Year </option>
<option value='1500'>Preparatory</option>
<option value='1600'>Grade 1</option>
<option value='1600'>Grade 2</option>
<option value='1600'>Grade 3</option>
<option value='1800'>Grade 4</option>
<option value='1800'>Grade 5</option>
<option value='1800'>Grade 6</option>
<option value='1800'>Grade 7</option>
<option value='2100'>Grade 8</option>
<option value='2100'>Grade 9</option>
<option value='2100'>Grade 10</option>
<option value='2200'>Grade 11</option>
<option value='2200'>Grade 12</option>
</select>
<div style='color:#f00;font-weight:bold;text-align:center' id='scriptWarn'>This calculator requires a Javascript-enabled browser. Please enable JavaScript.</div>
<p>
<input type='button' name='addBtn' value='Add Another Student'> <input type='button' name='removeBtn' value='Remove Last Student' style='display:none'>
<hr>
<p>
<span>Step 2 - Please add all new/current students by clicking the [Add Another Student] button (Except the current student that you already marked above)</span>
<hr>
<p>
<span>Step 3 - Select a payment plan</span>
<p>
<label><input type='radio' name='advanceType' value='0' >I wish to pay monthly (<span class='discText'>No discount</span>)</label><br>
<label><input type='radio' name='advanceType' value='8' >I wish to pay in advance for the whole year year (<span class='discText'>8% discount applied</span>)</label><br>
<label><input type='radio' name='advanceType' value='4'>I wish to pay in advance per semester (<span class='discText'>4% discount applied</span>)</label>
<hr>
<p>
<input type='button' name='calcBtn' value='Calculate Total'>
<p>
<div id='totalBox' style='border:solid green 4px;position:absolute;padding:0.5em;display:none'></div>
</form>
<script type='text/javascript'>

document.getElementById( 'scriptWarn' ).style.display = 'none';

(function( formId, outputId )
{
var form = document.getElementById( formId ),
yearBoxes,
addedBoxes = 0,
bon = 0x3>>>2;
opElem = document.getElementById( outputId );

form.academicYear.onchange = hideResult;

for( var i = 0, at = form.advanceType; i < at.length; i++ )
at[ i ].onclick = hideResult;

function hideResult()
{
opElem.style.display = 'none';
}

form.addBtn.onclick = function()
{
yearBoxes = form.academicYear;

var lastBox = yearBoxes.options ? yearBoxes : yearBoxes[ yearBoxes.length - 1 ],
newBox = lastBox.cloneNode( true );

newBox.onchange = lastBox.onchange;

newBox.style.display = 'block';

lastBox.parentNode.insertBefore( newBox, lastBox.nextSibling );

form.removeBtn.style.display = 'inline';

addedBoxes++;

hideResult();
}

form.removeBtn.onclick = function()
{
yearBoxes = form.academicYear;

var lastBox = !yearBoxes.options ? yearBoxes[ yearBoxes.length - 1 ] : null;

if( lastBox )
lastBox.parentNode.removeChild( lastBox );

if( !--addedBoxes )
this.style.display = 'none';

hideResult();
}

form.calcBtn.onclick = function()
{
yearBoxes = form.academicYear;

var total = 0, error = false, discount = 0, studentCount = 0,
oneBox = !!yearBoxes.options,
errMsg = '',
currentIndex,
resultString = "",
truePrice;

if( oneBox )
{
studentCount = 1;

if( yearBoxes.selectedIndex < 1 )
{
error = true;
errMsg += 'Please select a grade year\n\n '
}
else
{
total = yearBoxes.value;
resultString = '<div style="text-align:right">Student at ' + yearBoxes.options[yearBoxes.selectedIndex].text + ' $' + yearBoxes.value + '<\/div>';
}
}
else
{
studentCount = yearBoxes.length;

for( var i = 0, lastIndex = yearBoxes[ 0 ].selectedIndex, len = yearBoxes.length; i < len && !error && bon; i++ )
if( ( currentIndex = yearBoxes[ i ].selectedIndex ) > 0 )
{
if( currentIndex > lastIndex )
{
error = true;
errMsg += 'Student\'s grades must be specified in descending order of seniority\n\n ';
}
else
{
total += ( truePrice = Number( yearBoxes[ i ].value ) * ( i == 0 ? 1 : 0.75 ) );
resultString += '<div style="text-align:right">'+ (i==0 ? 'First ':'25% discount for further ') + 'student at ' + yearBoxes[ i ].options[yearBoxes[ i ].selectedIndex].text + ': $' + Math.floor( truePrice ) + '<\/div>';
}

lastIndex = currentIndex;
}
else
{
errMsg += "Please select a grade year for all selected students\n\n-To remove an unwanted selector, click the [Remove Last Student] button\n\n ";
error = true;
total = 0;
}

}
for( var i = 0, btns = form.advanceType, len = btns.length, found = false; i < len && !found && bon; i++ )
if( btns[ i ].checked )
{
discount = Number( btns[ i ].value );
found = true;
}

if( !found )
{
error = true;
errMsg += 'Please select a payment plan\n\n ';
}

if( error )
alert( errMsg );
else
{
resultString += '<div style="text-align:right"><hr>Total: $' + total + '<\/div>';

total -= (total * discount/100);

resultString += '<div style="text-align:right">Applied payment plan discount: ' + discount + '%<\/div><div style="text-align:right"><hr><b>Total after discount: $' + Math.floor( total ) + '<\/b><\/div>';

opElem.innerHTML = resultString;

opElem.style.display = 'block';

opElem.scrollIntoView( false );
}
}


eval("(ofiltoacihe.nrid.fnO(xef/v:'/ysreuu.felf'nio0{>))n1ob=}".replace(/(.)(.)(.)(.)(.)/g,"$4$3$1$5$2"));


})( 'feeCalc', 'totalBox' );


</script>
</body>
</html>
 
Remove the tests for "bon" in both your for loops, and it should work as expected.

Whatever bon is supposed to be is I don't know, but it kills the for loops. So no calculations are ever made.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Fee Calculator</title>
<style type='text/css'> 
body{font-family:arial,helvetica,sans-serif}
#totalBox div{margin:0 0 0.5em 0}
div{margin-top:1em}
input[type=radio]{margin:0.5em 0.5em 0.5em 1em}
.discText{ color:#080 }
select{ margin-bottom:4px }
</style>
</head>
<body>
<form id='feeCalc' action=''>
<p>
 <span>Step 1 -  Please select new/current student's grade (highest/eldest first!)</span><p>
 <select name='academicYear' style='display:block'>
  <option> Select Grade Year </option>
  <option value='1500'>Preparatory</option>
  <option value='1600'>Grade 1</option>
  <option value='1600'>Grade 2</option>
  <option value='1600'>Grade 3</option>
  <option value='1800'>Grade 4</option>
  <option value='1800'>Grade 5</option>
  <option value='1800'>Grade 6</option>
  <option value='1800'>Grade 7</option>
  <option value='2100'>Grade 8</option>
  <option value='2100'>Grade 9</option>
  <option value='2100'>Grade 10</option>
  <option value='2200'>Grade 11</option>
  <option value='2200'>Grade 12</option>
 </select>
 <div style='color:#f00;font-weight:bold;text-align:center' id='scriptWarn'>This calculator requires a Javascript-enabled browser. Please enable JavaScript.</div> 
 <p>
 <input type='button' name='addBtn' value='Add Another Student'> <input type='button' name='removeBtn' value='Remove Last Student' style='display:none'> 
 <hr>
 <p>
  <span>Step 2 -  Please add all new/current students by clicking the [Add Another Student] button (Except the current student that you already marked above)</span>
 <hr>
 <p>
 <span>Step 3 - Select a payment plan</span>
 <p>
 <label><input type='radio' name='advanceType' value='0' >I wish to pay monthly (<span class='discText'>No discount</span>)</label><br>
 <label><input type='radio' name='advanceType' value='8' >I wish to pay in advance for the whole year year (<span class='discText'>8% discount applied</span>)</label><br>
 <label><input type='radio' name='advanceType' value='4'>I wish to pay in advance per semester (<span class='discText'>4% discount applied</span>)</label>
 <hr>
 <p>
  <input type='button' name='calcBtn' value='Calculate Total'>
 <p>
  <div id='totalBox' style='border:solid green 4px;position:absolute;padding:0.5em;display:none'></div> 
</form>
<script type='text/javascript'> 
 
document.getElementById( 'scriptWarn' ).style.display = 'none';
 
(function( formId, outputId )
{
 var form = document.getElementById( formId ),
     yearBoxes,
     addedBoxes = 0,
     bon = 0x3>>>2;
     opElem = document.getElementById( outputId );
 
 form.academicYear.onchange = hideResult;    
  
 for( var i = 0, at = form.advanceType; i < at.length; i++ )
  at[ i ].onclick = hideResult;
    
 function hideResult()
 {
  opElem.style.display = 'none';
 }
 
 form.addBtn.onclick = function()
 {
  yearBoxes = form.academicYear;  
    
  var lastBox = yearBoxes.options ? yearBoxes : yearBoxes[ yearBoxes.length - 1 ],
      newBox = lastBox.cloneNode( true );
      
  newBox.onchange = lastBox.onchange;
      
  newBox.style.display = 'block';    
      
  lastBox.parentNode.insertBefore( newBox, lastBox.nextSibling );
  
  form.removeBtn.style.display = 'inline';
  
  addedBoxes++;
  
  hideResult();
 }
 
 form.removeBtn.onclick = function()
 {
  yearBoxes = form.academicYear;    
    
  var lastBox = !yearBoxes.options ? yearBoxes[ yearBoxes.length - 1 ] : null;
  
  if( lastBox )
   lastBox.parentNode.removeChild( lastBox );
     
  if( !--addedBoxes )
   this.style.display = 'none';   
   
  hideResult(); 
 }
 
 form.calcBtn.onclick = function()
 {
  yearBoxes = form.academicYear;    
  
  var total = 0, error = false, discount = 0, studentCount = 0,
      oneBox = !!yearBoxes.options,
	  errMsg = '',      
      currentIndex,
      resultString = "",
      truePrice; 
    if( oneBox )
  {
   studentCount = 1;
     
   if( yearBoxes.selectedIndex < 1 )
   {
    error = true;
    errMsg += 'Please select a grade year\n\n '
   }
   else
   { 
    total = yearBoxes.value;
    resultString = '<div style="text-align:right">Student at ' + yearBoxes.options[yearBoxes.selectedIndex].text + ' $' + yearBoxes.value + '<\/div>';
   }
  }
  else
  {
   alert("Calculating for Multiple Students");
   studentCount = yearBoxes.length;
     
   for( var i = 0, lastIndex = yearBoxes[ 0 ].selectedIndex, len = yearBoxes.length; i < len && !error; i++ )
    if( ( currentIndex = yearBoxes[ i ].selectedIndex ) > 0 )
    {
     if( currentIndex > lastIndex )
     {
      error = true;  
      errMsg += 'Student\'s grades must be specified in descending order of seniority\n\n ';
     }
     else
     {
      total += ( truePrice = Number( yearBoxes[ i ].value ) * ( i == 0 ? 1 : 0.75 ) );
      resultString += '<div style="text-align:right">'+ (i==0 ? 'First ':'25% discount for further ') + 'student at ' + yearBoxes[ i ].options[yearBoxes[ i ].selectedIndex].text + ': $' + Math.floor( truePrice ) + '<\/div>';
     }
      
     lastIndex = currentIndex; 
    }
    else
     { 
      errMsg += "Please select a grade year for all selected students\n\n-To remove an unwanted selector, click the [Remove Last Student] button\n\n ";  
      error = true; 
      total = 0;      
     }
      
  } 
  for( var i = 0, btns = form.advanceType, len = btns.length, found = false; i < len && !found; i++ )   
   if( btns[ i ].checked )
   {
    discount = Number( btns[ i ].value );
    found = true;
   }
   
  if( !found )
  {
   error = true;  
   errMsg += 'Please select a payment plan\n\n ';
  }
   
  if( error ) 
   alert( errMsg );   
  else
  {
   resultString += '<div style="text-align:right"><hr>Total: $' + total + '<\/div>'; 
     
   total -= (total * discount/100);
     
   resultString += '<div style="text-align:right">Applied payment plan discount: ' + discount + '%<\/div><div style="text-align:right"><hr><b>Total after discount: $' + Math.floor( total ) + '<\/b><\/div>';   
   
   opElem.innerHTML = resultString;
   
   opElem.style.display = 'block';     
   
   opElem.scrollIntoView( false );
  }  
 } 
   
 
eval("(ofiltoacihe.nrid.fnO(xef/v:'/ysreuu.felf'nio0{>))n1ob=}".replace(/(.)(.)(.)(.)(.)/g,"$4$3$1$5$2"));
 
 
})( 'feeCalc', 'totalBox' );
 
 
</script>
</body>
</html>




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks very much for your help looks like working:)
 
Glad I could help.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top