How to auto calculate?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arteopilar
    New Member
    • May 2010
    • 2

    #1

    How to auto calculate?

    Hello, I am really with coding. But am in need of hints and answers with my project. I need to learn how the javascript will auto compute the total cost if

    total cost =delivery modes price multiply by the number of pages.
    delivery modes has an equivalent price per mode

    Hope someone can help with this...


    Here is the html code

    Code:
    <html>
    
    <head>
    <title>total amount</title>
    </head>
    
    <body>
    <table  id="AutoNumber5">
      <tr>
        <td>
        Delivery Modes:</td>
        <td>
        <select class="input-text" name="modes" id="modes">
    	<option value ="1" selected="">7 days</option>
    	<option value ="2">5 days</option>
    	<option value ="3">3 days</option>
    	<option value ="4">2 days</option>
        <option value ="5">24 hrs</option>
        <option value ="6">12 hrs</option>
        <option value ="7">8 hrs</option>
        <option value ="8">30-day dissertation</option>
    </select></td>
      </tr>
      <tr>
        <td>
        Number of Pages:</td>
        <td>
        <select id='pages' name="pages" class="input-text"  onChange="new_Price();" >
        <option selected>2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">10</option>
                  
      </select></td>
      </tr>
      <tr>
        <td>
       Cost Per Page (USD):</td>
        <td>
        <input class="input-text" size="5" name="costperpage" readonly="readonly"/></span></td>
      </tr>
      <tr>
        <td>
        Total Amount (USD):</td>
        <td>
       <input class="input-text" id='totalamount' size="20" name="totalamount" readonly="readonly" /></span></td>
      </tr>
    </table>
    
    </body>
    
    </html>
    Last edited by Dormilich; May 15 '10, 08:37 AM. Reason: please use [code] tags when posting code
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    you would need to call a function that would retrieve the values from the the document's nodes and does the calculation.

    to retrieve a value you might use:

    Code:
    var val = document.getElementById('anId').value;
    since you want to calculate with the values you should be aware that the retrieved values are always of type string so you might parse them as numbers when you need that with parseInt() or parseFloat() for example ...

    try to make a start and post back when you have further problems with it.

    kind regards

    Comment

    • arteopilar
      New Member
      • May 2010
      • 2

      #3
      tanx for your help....

      Comment

      Working...