0

I need to calculate the number on selections. Im using the value as reference I dont need my function to add the values I need to add the number of fully successful, exceptional, or need imporvements. Here is a code I have but it calculating the total based on the value

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript">
    function calcTotal(oForm){
        var sum = 0;
        for(i=0; i < oSels.length; i++){
            sum += new Number(oSels[i].value);
        }
        document.getElementById('result').innerHTML = sum;
        return false;
    }
    window.onload=function(){
        oSels = document.getElementById('form1').getElementsByTagName('select');
        for(i=0; i < oSels.length; i++){
            oSels[i].onchange=function(){
                document.getElementById('result').innerHTML = '';
            }
        }
    }
    </script>
    </head>
    <body>
        <form id="form1" action="" method="post" onsubmit="return calcTotal(this)">
            <select name=select1>
                <option selected="selected" value="1">Fully Successful</option>
                <option value="2">Exceptional</option>
                <option value="3">Needs Improvement</option>
            </select>
            <br />
            <select name=select2>
                <option selected="selected" value="1">Fully Successful</option>
                <option value="2">Exceptional</option>
                <option value="3">Needs Improvement</option>
            </select>
            <br />
            <input name="" type="submit" value="Total" />
            <span>Total: </span><span id="result"></span>
        </form>
    </body>
</html>
3
Contributors
2
Replies
24
Views
4 Years
Discussion Span
Last Post by theHop
0

I need to calculate the number on selections. Im using the value as reference I dont need my function to add the values I need to add the number of fully successful, exceptional, or need imporvements. Here is a code I have but it calculating the total based on the value

What does this line mean:

for(i=0; i < oSels.length; i++){
sum += new Number(oSels[i].value);
}

If you written this code then you will ask a different question than the one you ask above.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.