i need to sum anything that is input in input form numbers. And this has to be in order like 5,4,3 and then it has to sum like 5+4+3 = 12. Can anyone help? I came as far as the code shows above.

this is the example of how it should be: link

thanks

The code:

<html>
    <head>
        <title>Vaja 6.2</title>

        <script src="http://code.jquery.com/jquery-latest.js"></script>
        <script type='text/javascript'>
            function preveri(elem)
            {
                    var iskanje=prompt("Vnesi iskano stevilo:");
                    var numericExpression = iskanje;
                
                    if (elem.value.match(numericExpression))
                    {
                        alert('Stevilo je v seznamu');
                    }else
                {
                    alert('Stevilo ni v seznamu');
                }

            }
            
            function sestej()
            {
                document.getElementById(numbers);
                document.write(numbers);
            }

            </script>
        
    </head>
    <body >
        <form>
            <input type='text' id='numbers'/>
            <input type='button' onclick="preveri(document.getElementById('numbers'))", value='Išči' />
        </form>
        <script>
            sestej();
        </script>

    </body>
</html>

Edited 5 Years Ago by minghags: n/a

Please can anyone help? I got this far:

<html>
    <head>
        <title>Vaja 6.2</title>

        <script type='text/javascript'>

            function preveri(elem)
            {
                    var iskanje=prompt("Vnesi iskano stevilo:");
                    var numericExpression = iskanje;
                
                    if (elem.value.match(numericExpression))
                    {
                        alert('Stevilo je v seznamu');
                    }else
                {
                    alert('Stevilo ni v seznamu');
                }

                var str=elem.value;
                
                document.getElementById('span').innerHTML = document.write(str.split(",") + "<br />");;
            }
            

            </script>
        
    </head>
    <body >
        <form>
            <input type='text' id='numbers'/>
            <input type='button' onclick="preveri(document.getElementById('numbers'));", value='I&#353;&#269;i' /><span id="span"></span>
        </form>

    </body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">

<html>
<head>
<title></title>

<script>

function calculate(){
    var numbers = document.getElementById('txtNumbers').value.replace(' ', '').split(',');
    var total = 0;


    for(var i = 0; i < numbers.length; i++){
        total += parseFloat(numbers[i]);
    }

    document.getElementById('results').innerHTML = total.toString();
}

</script>

</head>
<body>

<input id="txtNumbers" type="text" /><button onclick="calculate();">Calculate</button><span id="results"></span>


</body>
</html>

Edited 3 Years Ago by pyTony: Fixed formating

If you could help me with one more problem in same program i would really appreciate it. Thanks

Upgrade Javascript so that when you click on the button with the first regular expression to check whether all input box containing the appropriate list of numbers (or a list of correctly spelled and separated by commas). Use the following regular expression: (^ [0-9] (\ s * [0-9 ])+$). To check, use regexp class. In case of wrong input, notify user (in the element span) and the entry and search is not made.

BTW, i did like this:

<html>
    <head>
        <title>Vaja 6.2</title>

        <script type='text/javascript'>

            function preveri(elem)
            {
                    var iskanje=prompt("Vnesi iskano stevilo:");
                    var numericExpression = iskanje;
                
                    if (elem.value.match(numericExpression))
                    {
                        alert('Stevilo je v seznamu');
                    }else
                {
                    alert('Stevilo ni v seznamu');
                }

            }
            
            function izracun(){
                var numbers = document.getElementById('numbers').value.replace(' ', '').split(',');
                var total = 0;
                
                
                for(var i = 0; i < numbers.length; i++){
                    total += parseFloat(numbers[i]);
                }
                
                document.getElementById('rezultat').innerHTML = total.toString();
            }
            

            </script>
        
    </head>
    <body >
        <form>
            <input type='text' id='numbers'/>
            <input type='button' onclick="preveri(document.getElementById('numbers')); izracun();", value='I&#353;&#269;i' /><span id="rezultat"></span>
        </form>

    </body>
</html>

Edited 5 Years Ago by minghags: n/a

This question has already been answered. Start a new discussion instead.