Can I lock / block a text field, once data is entered so that it can not be changed any more?

Dafink
Dafink Göttingen, GermanyCommunity Member Qubie ✭
edited July 13 in Custom Code

When using this "${rand://int/1:500}", a random number is generated in a text field. Now the issue is that subjects can still reenter a new value according to there preference. Is there a possibility to lock the text field once the random number appears. I need a text field since I am supposed to reference and compare the random number with a previously entered number in a way if it is smaller or bigger.

Other option could be to use HTML like this:
"
You genereate a random number P


Ihr Marktpreis P für den Becher lautet:

function myFunction() { document.getElementById("number").value = Math.floor((Math.random() * 500) + 1); document.getElementById("number").disabled = true; document.getElementById("random").disabled = true; }

"

Can I compare subjects' previously entered number with the random one generated via HTML. How do I reference to an HTML code? Many Thanks for your support.

Best Answers

  • TomG
    TomG Raleigh, NCCommunity Member, Qualtrics Brand Admin Wizard ✭✭✭✭✭
    Accepted Answer

    @Dafink said:
    Ok, thanks a lot Tom!
    Can I apply the "read only" command as javascript to image attached? The questions produce the random between 1: 500 and subjects are not allowed to change it. Do you know what I mean?

    (https://us.v-cdn.net/6030293/uploads/editor/ds/7lvht80fni3z.png "")

    Yes:

    Qualtrics.SurveyEngine.addOnload(function() {
        jQuery("#"+this.questionId+" .InputText").prop("readonly", true);
    });
    
  • Akdashboard
    Akdashboard South CarolinaCommunity Member Superuser ✭✭✭✭
    Accepted Answer

    @Dafink - I know you already got an answer to this, but it requires additional programming knowledge and the solution wouldn't (technically) be supported by Qualtrics Support. So I wanted to propose a solution that doesn't require additional programming and would be supported by Q Support.

    Since you need to reference the randomly generated number at some other point, why not create the random number as an embedded data value in the survey flow and pipe it in as needed. Since it will be embedded data, you can always reference the number generated and the respondent won't be able to change it.

Answers

  • TomG
    TomG Raleigh, NCCommunity Member, Qualtrics Brand Admin Wizard ✭✭✭✭✭

    You can "lock" the text input field using the readonly attribute.

    document.getElementById('random').readOnly = true;
    

    Although, "random" or "number" aren't the ids Qualtrics text entry fields.

  • Dafink
    Dafink Göttingen, GermanyCommunity Member Qubie ✭

    Ok, thanks a lot Tom!
    Can I apply the "read only" command as javascript to image attached? The questions produce the random between 1: 500 and subjects are not allowed to change it. Do you know what I mean?

    (https://us.v-cdn.net/6030293/uploads/editor/ds/7lvht80fni3z.png "")

  • Dafink
    Dafink Göttingen, GermanyCommunity Member Qubie ✭

    I ll try it out now. Will give you feedback if that worked! :)

  • Dafink
    Dafink Göttingen, GermanyCommunity Member Qubie ✭
    edited August 2019

    Thanks again Tom! It worked well! Do you have a script or some details from which I can get more of the syntax you are using in qualtrics?

  • TomG
    TomG Raleigh, NCCommunity Member, Qualtrics Brand Admin Wizard ✭✭✭✭✭

    @Dafink said:
    Thanks again Tom! It worked well! Do you have a script or some details from which I can get more of the syntax you are using in qualtrics?

    Qualtrics html elements vary by question type and layout. My advice is...
    1. Get familiar with jQuery
    2. Use your browser's Inspect feature

  • Dafink
    Dafink Göttingen, GermanyCommunity Member Qubie ✭

    @Akdashboard - thanks for getting back as well. Amazing Community!

    I tried out your solution as well. It works fine for me too and I will reconsider both options for the experiment.

    Have a great day.

  • Sathwik_Teja
    Sathwik_Teja Telangana, IndiaCommunity Member, Qualtrics Brand Admin Qubie ✭

    This script was not working on a Org Hierarchy question.

    How to make the Org Hierarchy question as read only text.