1.11M Members

How to display value of selected item(dropdown list) on textbox


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);


You can try this demo:

<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;
<form action="<?php /*><!--*/ echo $_SERVER['PHP_SELF']; /*--><?*/ ?>" onsubmit="return caculateFee(this);">
<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>


I dont know it is correct or not but try using

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!

This article has been dead for over six months: Start a new discussion instead
Start New Discussion
Tags Related to this Article