Unique ID widget: Use conditional logic on the ID value

  • Profile Image
    Asked on September 14, 2015 at 08:11 PM

    Well, here's another one that may be impossible, but I'm throwing it out there. 

    We're and academic institution, and we have this experiment we're running. I added a hidden user counter at the very top. I want odd-number users to see certain questions and even-numbered to see others. So when participant/user number 7, for example, reaches question 12, he or she will get a question from group A. Participant/user 8 will get a question from Group B. As you can see on the form, I made extensive use of the collapse, but maybe there's something I can do with the Update Field Calculations. To be honest, it's the one part of jotform I'm light on. Perhaps if i can get an equation that reads "If the final digit is odd, then show question A. If even, show Question B."

    Oof, I know this is an impossibly tall order, but it was a last-minute request from the designers. Let me know if I need to clarify.







  • Profile Image
    Answered on September 15, 2015 at 06:13 AM


    I believe this should be possible using modulo.

    If you just want to show questions based from the participant number if it's odd or even, then you can use this formula:

    IF participant number modulo 2 IS EQUAL to 0 then it is even

    IF participant number modulo 2 is greater than 0 then it is odd


    Unfortunately, the problem is that the Unique ID widget value cannot be used in the conditional logic, so we can't fetch it and use it for calculation. I will forward this to our widget team as I believe the Unique ID would be very efficient if it can be used in the calculation.


    However, there's another way to do this, here's a sample web page with the cloned form I have: https://shots.jotform.com/charlie/Custom%20Form%20Thread662047/counting%20unique%20ID.html. This is how I did mine:

    1. First, I get the form's full source code or the script embed code.

    2. I then added a Javascript function to identify if the ID number is odd or even. You can check my page source code to see how I set it up. You can also check this quick guide about using modulo to identify odd or even numbers.

    3. This is how I set my Javascript function:

    function numAnalysis() {

    var numID = document.getElementById("input_15").value;


    var numType;



    if((numID % 2) == 0) {

    alert('Even number');

    numType = "even"

    } else if((numID % 2) > 0) {

    alert('Odd number');

    numType = "odd"



           // output the number type in the text box input named "Output ID on Textbox"

    document.getElementById("input_771").value = numType;



    4. Basically what the code above do is it checks if the numID is odd or even, then it sets the textbox with the text string "odd" or "even". You can then use that text box for conditional logic.

    However, you need to have some basic to intermediate knowledge on programming using Javascript to do this.


    I have already forwarded the request to make the Unique ID widget value to be used in the calculation, although I'm not sure if the widget team could implement this anytime soon. That would make things more easier and no need to use your own custom Javascript code.

    We will update you on this thread as soon as this has been implemented.


  • Profile Image
    Answered on September 16, 2015 at 06:38 AM

    After I modify the script, though, then I would have to host the form on my own site. Correct? Unless I've been misunderstanding the explanations, there's no way to make any script changes without them being immediately stripped by jotform.

  • Profile Image
    Answered on September 16, 2015 at 09:19 AM

    Yes, unfortunately, you need to embed your code on a website page. You're not necessarily hosting the whole form as there are still scripts that are being loaded in our end and the submission will directly be saved in our servers. Getting the form's source code will give you a flexibility to manipulate the form fields directly, add your own function or make advance scripts.

    I hope that helps.