Input box id in formula type questions

Input box id in formula type questions

by Manish Varma -
Number of replies: 1

Hello,

I have defined a variable in JS lets say it is x.

now I want the value of x as input in first input box of formula type question.


<!--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>

I am tring to use the code above in the html of the question but it does not seem to work. Please help

Average of ratings: -
In reply to Manish Varma

Re: Input box id in formula type questions

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

To input x , the syntax is $("input.formulas_number:eq(0)").val({x});

You could put this line in a function triggered by clicking the check button: $('.submit').on('click', foobar); and maybe other navigation buttons:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(window).on("load", function() {

    $('.submit').on('click', foobar);
    $('.submitbtns').on('click', foobar);
    function foobar() {
        $("input.formulas_number:eq(0)").val({x});
    }
});
</script>

To change a value, in the answer box, that has been checked, use $("input.formulas_number:eq(0)").attr("value",{x});