formula questions - distribute values

Re: formula questions - distribute values

by Dominique Bauer -
Number of replies: 0
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Salam Ahmad,

To put the value of a variable, say x, defined in the variables, into the first answer box, place the following code in the HTML of the question text:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
    $(document).ready(function() {
        $("input.formulas_number:eq(0):text").val({x});
    });
</script>

If you want to put a value in the second answer box, replace :eq(0) with :eq(1), etc. (index starts at 0).

If you want to put a constant value in an answer box, replace {x} with the value, for example 40 or 2.

If you want to put values in more than one box, repeat the line starting with $("input...