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>

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

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.

do you mean you want to count how many dropdowns have a selection at all?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.