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
Reply

Join Date: Mar 2009
Posts: 1
Reputation: alfalisyada is an unknown quantity at this point 
Solved Threads: 0
alfalisyada alfalisyada is offline Offline
Newbie Poster

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

 
0
  #1
Mar 16th, 2009
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>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

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

 
0
  #2
Mar 17th, 2009
You can try this demo:
  1. <html>
  2. <head>
  3. <title></title>
  4. <script type="text/javascript">
  5. <!--
  6. function caculateFee(form) {
  7. if ( form ) {
  8. with ( form ) {
  9. var payamount = parseFloat( txtpayamount.value );
  10. var courses = course.selectedIndex;
  11. txtbalfee.value = (((course.options[courses].value) * 1) - payamount);
  12. }
  13. } return false;
  14. }
  15. //-->
  16. </script>
  17. </head>
  18. <body>
  19. <form action="<?php /*><!--*/ echo $_SERVER['PHP_SELF']; /*--><?*/ ?>" onsubmit="return caculateFee(this);">
  20. <div>
  21. <label for="course"><strong>Courses:</strong></label><br />
  22. <select id="course" name="course" size="1">
  23. <option value="0.00">Please select a course</option>
  24. <option value="19000">Multimedia</option>
  25. <option value="17000">Computer Science</option>
  26. </select><br />
  27. <label for="txtpayamount">Payment: <input type="text" id="txtpayamount" name="txtpayamount" value="0.00" size="20" /></label><br />
  28. <label for="txtbalfee">Total: <input type="text" id="txtbalfee" name="txtbalfee" value="0.00" size="20" /></label>
  29. </div>
  30. </form>
  31.  
  32. </body>
  33. </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: danishbacker is an unknown quantity at this point 
Solved Threads: 5
danishbacker's Avatar
danishbacker danishbacker is offline Offline
Junior Poster in Training

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

 
0
  #3
Mar 17th, 2009
I dont know it is correct or not but try using
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.getElementById("anyName")
  2. or
  3. 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!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC