Test





    <div id="results">

    </div>


    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script>
        // Größte zuerst
        var containerSizes = [6, 3, 1]

        $(document).ready(function () {
            $('#form').on('submit', function (e) {
                e.preventDefault()

                var length = parseFloat($('#boxLength').val().replace(',', '.'))
                var width = parseFloat($('#boxWidth').val().replace(',', '.'))
                var height = parseFloat($('#substratHeight').val().replace(',', '.'))

                var liter = (length * width * height) / 1000
                var containerAmounts = []

                var tempLiter = Math.ceil(liter)
                for (var i = 0; i < containerSizes.length; i++) {
                    var size = containerSizes[i]
                    if (size > tempLiter) {
                        containerAmounts.push(0)
                        continue
                    }

                    var amount = (tempLiter - (tempLiter % size)) / size
                    tempLiter -= amount * size
                    containerAmounts.push(amount)
                }


                $('#results').empty()
                $('#results').append('<h4>Du brauchst ' + liter.toString().replace('.', ',') + ' Liter Substrat</h4>')
                for (var i = 0; i < containerAmounts.length; i++) {
                    var size = containerSizes[i]
                    var amount = containerAmounts[i]

                    if (amount > 0) {
                        $('#results').append('<p>' + amount + ' mal ' + size + ' Liter Sack/Säcke</p>')
                    }
                }
            })
        })
    </script>