| | |
How to display value of selected item(dropdown list) on textbox
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
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>
<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:
javascript Syntax (Toggle Plain Text)
<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>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
I dont know it is correct or not but try using
for handling items in the DOM instead of forms[i]
i think this will avoid confusion
forgive me if this doesn't work!
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.getElementById("anyName") or document.getElementByName("anyName") or something like this
i think this will avoid confusion

forgive me if this doesn't work!
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: How to create button using innerHtml
- Next Thread: Set Session variable in JS-ASP.net with C#
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor decimal dependent design disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword html htmlform ie8 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl listbox math media microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player post problem progressbar regex runtime scroll search security select shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





