hi..i need some ideas...I want to calculate student fees payment on my php page, but my coding here its not working. One more thing is when selected item click and its can display value of the item in other textbox(ex: if course Diploma Multimedia is selected, then the course fee is 19000 is display on txtCourseFee).I'm using java script for the calculation and save into mysql database. The code is here :

<script language="JavaScript" type="text/javascript">
function CalculateFee (form)
{
var coursefee;
var payamaount = form.txtpayamount.value; (user input)
var balfee;
balfee = (coursefee - payamount);

if (document.form.course[0].selected)
Diploma Multimedia = 19000;
coursefee = Diploma Multimedia;

else if (document.form.course[1].selected)
Diploma Computer Science = 17000;
coursefee = Diploma Computer Science;
form.txtbalfee.value = (balfee);
}
</script>

You can try this demo:

<html>
<head>
<title></title>
<script type="text/javascript">
<!--
function caculateFee(form) {
if ( form ) {
   with ( form ) {
   var payamount = parseFloat( txtpayamount.value );
   var courses = course.selectedIndex;
    txtbalfee.value = (((course.options[courses].value) * 1) - payamount); 
    }
  } return false;
}
//-->
</script>
</head>
<body>
<form action="<?php /*><!--*/ echo $_SERVER['PHP_SELF']; /*--><?*/ ?>" onsubmit="return caculateFee(this);">
<div>
<label for="course"><strong>Courses:</strong></label><br />
<select id="course" name="course" size="1">
<option value="0.00">Please select a course</option>
<option value="19000">Multimedia</option>
<option value="17000">Computer Science</option>
</select><br />
<label for="txtpayamount">Payment: <input type="text" id="txtpayamount" name="txtpayamount" value="0.00" size="20" /></label><br />
<label for="txtbalfee">Total: <input type="text" id="txtbalfee" name="txtbalfee" value="0.00" size="20" /></label>
</div>
</form>

</body>
</html>

I dont know it is correct or not but try using

document.getElementById("anyName")
or
document.getElementByName("anyName") or something like this

for handling items in the DOM instead of forms

i think this will avoid confusion :)
forgive me if this doesn't work!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.