954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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 :

alfalisyada
Newbie Poster
1 post since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

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>
<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>
<label for="txtpayamount">Payment: <input type="text" id="txtpayamount" name="txtpayamount" value="0.00" size="20" /></label>
<label for="txtbalfee">Total: <input type="text" id="txtbalfee" name="txtbalfee" value="0.00" size="20" /></label>
</div>
</form>

</body>
</html>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

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]

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

danishbacker
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 10
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You