Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to calculate balance using java script from dropdown list

    hi..for now the course fee already can view in the txtcoursefee, but when i clicked the "calculate" button for get the balance fee seems it doesn't work. i already call the function (for calculate balance) at the "calculate" button. here is the code:

    Code:
    <html>
    <head>
    <title>Course Fees</title>
    <script language="JavaScript" type="text/javascript">
    
    function CalculateFee (CourseFeePair)
    {
    var CourseFee = CourseFeePair.split('|');
    var payamount = document.getElementById('txtpayamount').value; // (user input pay amount)
    var balfee = (CourseFee[1]*1) - (payamount*1);
    
    // Used desired display of following commands 
    document.getElementById('txtcoursefee').value = CourseFee[1];
    
    }
    </script>
    </head>
    <body>
    <form name="myForm" id="myForm">
    <select id="CourseFee" onChange="CalculateFee(this.value)">
    <option value="|0">Select Course</option>
    <option value="Diploma Multimedia|19000">Multimedia</option>
    <option value="Diploma Computer Science|17000">Computer Science</option>
    </select>
    <label>
    <input name="txtcoursefee" type="text" id="txtcoursefee">
    </label>
    <div id="Diploma" style="font-style:italics"></div>
    <p>
    Pay amount: <input name="txtpayamount" type="text" id="txtpayamount" value="0">
    <p>
    Balance:
    <label>
    <input name="txtbal" type="text" id="Balance"></input>
    </label>
    <p>
    <input type="button" name="Button" value="Calculate" onClick="CalculateFee(this.CourseFeePair)" /> //(button is click and dispay balance at txtbal)
    <label>
    <input type="submit" name="Submit" value="Save" />
    </label>
    <input type="reset" name="Reset" value="Cancel" />
    </p>
    </form>
    </body>
    </html>

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,065
    Thanks
    36
    Thanked 498 Times in 492 Posts

    Question Question ...

    What was wrong with the answer supplied here?
    http://www.dreamincode.net/forums/showtopic93304.htm


  •  

    Posting Permissions

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