Support » Plugin: Calculated Fields Form » Random functions

  • Resolved altkmv


    Hello there!

    Help to deal with the problem. I want to make button, when you press it – select randomly number. From 0 to 9. And, depending on the resulting number, the text field was shown.

    I tried to create a button and paste it “Math.floor (Math.random () * 10);”. And then try pass the value to the calculated field. But I did not succeed.

    Tell me, how to do it right?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople


    Hello @altkmv.

    The piece of code: Math.floor (Math.random () * 10); is correct, even if you are using our plugin it could be implemented as FLOOR(RANDOM()*10) without the Math object, but with your description it is not clear the way you are assigning the random number to the fields, or the way you are using this number.

    Please, send me the link to the webpage where the form is inserted and describe the process.

    Best regards.

    Here is the test page: . I want to understand the principle and do it right

    Plugin Author codepeople


    Hello @altkmv,

    The process was not implemented as should, you cannot use the button as an operand in the equation, because the buttons don’t have an onchange event. So, the equation would be as follows:

    1. Insert a hidden field in the form, I’ll call it the fieldname123
    2. Edit the onclick event of the button as follows:


    3. Finally, edit the equation associated to the calculated field to use the hidden field inserted in the first step.

    and that’s all.

    Note that the fields’ names are generated dynamically, so, in the previous code you should use the corresponding field’s name.

    Best regards.

    Thanks alot!

    Whether correctly I understood, I create a calculated field. By this equation I gain the value this calculated field and if the value is 1, then I output the field 1, the value 2 – the field 2, etc.?

    Apparently, I again understand everything is not entirely correct, because the display of the fields does not work (as if the field is always 0).

    Plugin Author codepeople


    Hello @altkmv,

    I’m sorry, I don’t understand what do you mean with the fields to display, but if you want to display some fields based on the equation’s results, you simply should defined dependencies in the settings of calculated field.

    By the way, I think that would be better if you move the code that generate the random number directly to the equation, run this code in the onclick event only for assigning the generated number to the calculated field, has no sense. In this case you can include the piece of code that generates the random number as part of the equation:

    return FLOOR(RANDOM()*10);

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Random functions’ is closed to new replies.