Advanced Search

Results 1 to 2 of 2

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

  1. #1
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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 :

    Code:
    <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>

  2. #2
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi

    Assuming you're using a select element for courses and that there is only one form in page you're script needs modifications.

    First:
    - Don't use blanks in variable names (as in Diploma Multimedia = 19000
    - Don't execute '(balfee = coursefee - payamount);' before you've assigned a value to coursefee since 'coursefee' won't contain anything at that moment.
    - Use the value attribute in the options elements to set the fee for each course, like:

    <select name="course" onchange="CalculateFee(document.forms[0])">
    <option value="19000">Diploma Multimedia</option>
    <option value="17000">Diploma Computer Science</option>
    ...
    </select>

    Try this one (assuming you trigger this function upon select onchange event)

    <script language="JavaScript" type="text/javascript">
    function CalculateFee (form) {
    coursefee = form.course.value; //If you use the options value attribute for course fees
    payamaount = form.txtpayamount.value; //(user input)
    balfee = (coursefee - payamount);
    form.txtbalfee.value = (balfee);
    }

    Hope this helps
    /R
    </script>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •