View Full Version : How to calculate balance using java script from dropdown list

03-19-2009, 04:36 PM
hi..for now the course fee already can view in the txtcoursefee, but when i clicked the "calculate" button for get the balance fee seems it doesn't work. i already call the function (for calculate balance) at the "calculate" button. here is the code:

<title>Course Fees</title>
<script language="JavaScript" type="text/javascript">

function CalculateFee (CourseFeePair)
var CourseFee = CourseFeePair.split('|');
var payamount = document.getElementById('txtpayamount').value; // (user input pay amount)
var balfee = (CourseFee[1]*1) - (payamount*1);

// Used desired display of following commands
document.getElementById('txtcoursefee').value = CourseFee[1];

<form name="myForm" id="myForm">
<select id="CourseFee" onChange="CalculateFee(this.value)">
<option value="|0">Select Course</option>
<option value="Diploma Multimedia|19000">Multimedia</option>
<option value="Diploma Computer Science|17000">Computer Science</option>
<input name="txtcoursefee" type="text" id="txtcoursefee">
<div id="Diploma" style="font-style:italics"></div>
Pay amount: <input name="txtpayamount" type="text" id="txtpayamount" value="0">
<input name="txtbal" type="text" id="Balance"></input>
<input type="button" name="Button" value="Calculate" onClick="CalculateFee(this.CourseFeePair)" /> //(button is click and dispay balance at txtbal)
<input type="submit" name="Submit" value="Save" />
<input type="reset" name="Reset" value="Cancel" />

03-19-2009, 05:30 PM
What was wrong with the answer supplied here?