Question - Type Formula -

Question - Type Formula -

by Marcelo Rodrigues -
Number of replies: 9

(Version 3.9) Hello everyone,

I wish you are healthy and at peace in your heart!

I would like to ask for help with the following problem:

1- I am working on a question, where the student will need to write the answer.

2- I would like that after the student writes to see the answer and move on to the next question, the written answer, be placed in an input text field.

3- Is this possible? Is there a way to use a script or javascript for this?

4- An example is attached. 

5- After answering value 1 "8", the number "8" needs to go to the input text - value 1, as shown by the arrow. The same action for number "9", for input text value 2.

Thank you, Marcelo.


Average of ratings: -
In reply to Marcelo Rodrigues

Re: Question - Type Formula -

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Marcelo,

May peace and health be with you too.

You can proceed by editing the HTML of the question text as follows.

Identify the two inputs with an id, for example:

...<p align="center"><input id="value1" type="text" size="5"></p>...
...<p align="center"><input id="value2" type="text" size="5"></p>...

Transfer the content of the answer boxes to the input boxes by adding the following code (also in the HTML of the question text): 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $("#value1").val($(".formulas_number:eq(0)").val());
    $("#value2").val($(".formulas_number:eq(1)").val());
});
</script>

In reply to Dominique Bauer

Re: Question - Type Formula -

by Marcelo Rodrigues -
Hi Professor Dominique,

Thank you so much for helping me again!

The code you sent transfers the values right after the student sends the question. This looks great was what I would like for the end of the question!

But I would also like that the moment the student types in the answer, the value is already transferred immediately in real time.

Would it be possible to maintain the final functioning together with this initial functioning?

Professor Dominique, thank you very much for your always precious and wonderful help!

Marcelo.
In reply to Marcelo Rodrigues

Re: Question - Type Formula -

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Marcelo,

You could add the following to the script:

    $(".formulas_number:eq(0)").keyup(function(){
        $("#value1").val($(".formulas_number:eq(0)").val());
    });
    $(".formulas_number:eq(1)").keyup(function(){
        $("#value2").val($(".formulas_number:eq(1)").val());
    });
In reply to Dominique Bauer

Re: Question - Type Formula -

by Marcelo Rodrigues -
Hi Professor Dominique,

Yes, it worked perfectly!

Thank you so much for sharing your wisdom and helping us!

Thank you very much!

Marcelo.
In reply to Dominique Bauer

Re: Question - Type Formula -

by Marcelo Rodrigues -

Hi Professor Dominique,

I wish you a great week!

I would like to ask you, if it would be possible, to adapt this script that you sent me, to get multiple-choice responses with drop-down menu.

I tried to make the multiple choice answer chosen by the student appear in the "Value 5" field, but I couldn't.

Teacher, thank you so much for everything!

Marcelo.

In reply to Marcelo Rodrigues

Re: Question - Type Formula -

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Marcelo,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function() {

    $("#value1").val($(".formulas_number:eq(0)").val());
    $("#value2").val($(".formulas_number:eq(1)").val());
    $("#value3").val($(".formulas_number:eq(2)").val());
    $("#value4").val($(".formulas_number:eq(3)").val());
    $("#value5").val( $(".formulas_menu option:selected").text() );

    $(".formulas_number:eq(0)").keyup(function() {
        $("#value1").val($(".formulas_number:eq(0)").val());
    });
    $(".formulas_number:eq(1)").keyup(function() {
        $("#value2").val($(".formulas_number:eq(1)").val());
    });
    $(".formulas_number:eq(2)").keyup(function() {
        $("#value3").val($(".formulas_number:eq(2)").val());
    });
    $(".formulas_number:eq(3)").keyup(function() {
        $("#value4").val($(".formulas_number:eq(3)").val());
    });
    $(".formulas_menu").click(function(){
       $(".formulas_menu select").click(function(){
            var i = parseInt($(this).val()) + 1;
            var x = $(".formulas_menu option:eq("+i+")").text();
            $("#value5").val(x);
        });
    });
});
</script>

Out of curiosity, can you tell us what it is for?

Atenciosamente.


In reply to Dominique Bauer

Re: Question - Type Formula -

by Marcelo Rodrigues -
Hi Professor Dominique,

I wish you well and healthy!

Thank you very much again for your precious help!

Yes, I will explain what it is for:

1- I am helping the Accounting teacher to compose a test using "question type formula";

2- There is a question that has 4 items, where the accounts used by accounting appear, similar to the question that exists on moodleformula.org;

3- However, this question is more extensive and includes: daily book, accounts, balance sheet for verification and balance sheet;

4- The Accounting teacher requested that when answering and classifying whether a given account is a debit or credit account, this answer should be replicated, in the other parts of the question where it is required, which facilitates the student's life.

5- The same goes for the values ​​found, which are reported in the other parts of the question.

6- For not knowing any other way to accomplish what the teacher asked, she was putting together each item as an answer and was already with 86 parts! ... lol

7- So, I asked you to help me. It is the first time that we have set up an issue with so many items for Accounting.

8- Professor Dominique, thank you very much for moodleformulas.org and for all the help that you have given us in such a kind and careful way!

Thank you very much!

Marcelo.
Average of ratings: Useful (1)
In reply to Marcelo Rodrigues

Re: Question - Type Formula -

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hello Marcelo,

I thought you might be interested also in duplicating the answers to other answer boxes and drop-down menus. You will find an example at MoodleDocs ↗, under Accounting / Bookkeeping / Entries.
In reply to Dominique Bauer

Re: Question - Type Formula -

by Marcelo Rodrigues -
Hi Professor Dominique,

I wish you and your whole family a week full of peace and health!

Yes I'm interested. I thought it was great to post what we talked about here on the forum, on Moodle.docs. Thank you very much.

It's great!

Thank you very much!

Marcelo.