SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Loop wont update running total

    Hello,

    I am new to Javascript and I am working on an exercise I found on a website.
    The problem is that my loops will not update the running total values in these functions I am keeping. I have having a hard time finding where the error is occuring and your help is appreciated.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    
    </head>
    <body>
    <h1>Configure Your GT Super Sportscar</h1>
    <form id="orderform" action="#">
    <table border="1">
    
    <tr>
    
    <td><input type="radio" name="manual" checked="checked" id="manual" value="17790.00" />GT Manual</td><td>$17,790.00</td> 
    </tr>
    <tr>
    <td><input type="radio" name="manual" id="auto" value="18590.00" />GT Automatic</td><td>$18,590.00</td>
    </tr>
    <tr>
    <td><input type="radio" name="manual" id="smanual" value="22455.00" />GT-S Manual</td><td>$22,455.00</td>
    </tr>
    <tr>
    <td><input type="radio" name="manual" id="sshift" value="23155.00"/>GT-S Sportshift</td><td>$23,155.00</td>
    </tr>
    </table>
    <table border="1">
    
    <tr>
    <td><input type="radio" name="manual" id="combo1" value="1235.00" />Option Combo #1</td><td>$1235.00</td>
    </tr>
    <tr>
    <td><input type="radio" name="manual" id="combo2" value="3354.00" />Option Combo #2
    <ul>
    <li>Rear Spoiler and Fog Lamps</li>
    <li>Keyless Entry</li>
    <li>Power Tint and Side Moonroof</li>
    <li>Power Windows, Doors, and Cruise Control</li>
    </ul>
    </td>
    <td>$3354.00</td>
    </tr>
    <tr>
    <td><input type="radio" name="manual" id="nocombo" value="0" />No Combo</td><td>$0</td>
    </tr>
    
    </table>
    <table border="1">
    
    <tr>
    
    <td><input type="checkbox" name="amen" id="cac" value="550.00"/>CD Autochanger</td><td>$550.00</td> 
    </tr>
    <tr>
    <td><input type="checkbox" name="amen" id="vss" value="399.00"/>VIP Security System</td><td>$399.00</td>
    </tr>
    <tr>
    <td><input type="checkbox" name="amen" id="adm" value="295.00"/>Auto Dimming Mirror</td><td>$295.00</td>
    </tr>
    
    </table>
    <table border="1">
    
    <tr>
    <td><input type="text" name="price" id="price" /></td><td><input type="button" onclick="showit()" value="Calculate Total" /></td>
    </tr>
    </table>
    </form>
    <script type="text/javascript">
    /**
    * @author Isaac's
    */
    function getval(){
    var options = document.forms["orderform"].manual;
    var optionslength = options.length;
    var total = 0;
    for (var i = 0; i &lt; optionslength; i++) {
    if (options[i].checked) {
    options[i].value += total;
    }
    return total;
    }
    }
    var result1 = getval();
    function getval2(){
    var total=0;
    var checkboxes = document.forms["orderform"].amen;
    for (var i = 0; i &lt; checkboxes.length; i++) {
    checkboxes[i].value += total;
    }
    return total;
    }
    
    var result2 = getval2();
    
    function showit(){
    var total = parseFloat(result1) + parseFloat(result2)
    alert(total);
    }
    
    </script> 
    </body>
    </html>

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have 2 function - getval() and getval2() which never get called as far as I can tell.

    The only function that is used by your code is showit() but it doesn't call either of the above 2 functions.


Tags for this Thread

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
  •