A
A
aial2017-05-06 17:20:47
JavaScript
aial, 2017-05-06 17:20:47

How to call a JavaScript function until the loop ends?

I have such a question while the cycle is running, then so many times you need to call the function.

{% for i in student_answers %}
               .......
{% endfor %}

if student_answers = 5 then the function should be called 5 times. Here is the JavaScript function
function plus_input() {
                $('.many-group:last').after(
                        '<div class="form-group many-group">\
                            <label>' + label_input + '</label>\
                    <div class="input-group">\
                        <input type="text" class="form-control many-input" name="student_answer" pattern=' + pattern + ' required>\
                        <span class="input-group-btn">\
                            <button class="btn btn-danger" onclick="minus_input(event)" type="button">-</button>\
                        </span>\
                    </div>\
                </div>');
            }

I did this but it doesn't work
{% for i in student_answers %}
                <body onload="plus_input()"></body>
{% endfor %}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2017-05-06
@LazyTalent

Python code is executed on the server side, and JS code is executed on the client side, i.e. in browser

R
romy4, 2017-05-06
@romy4

maybe so. I don't know how it is in your python

<body onload="for(var i=0; i<{% print student_answers.count %}; i++) { plus_input();}"></body>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question