Can I lock / block a text field, once data is entered so that it can not be changed any more? | XM Community
Skip to main content
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:

"

<button id="random" onclick="myFunction()"><b>You genereate a random number P</b></button>

<br>

<b>Ihr Marktpreis P für den Becher lautet:</b> <input type="number" id="number"><br><br>



<script>

function myFunction() {

document.getElementById("number").value = Math.floor((Math.random() * 500) + 1);

document.getElementById("number").disabled = true;

document.getElementById("random").disabled = true;

}

</script>

"



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.
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.
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://uploads-us-west-2.insided.com/qualtrics-us/attachment/ds_7lvht80fni3z.png "")
> @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://uploads-us-west-2.insided.com/qualtrics-us/attachment/ds_7lvht80fni3z.png "")

Yes:

```

Qualtrics.SurveyEngine.addOnload(function() {

jQuery("#"+this.questionId+" .InputText").prop("readonly", true);

});

```
I ll try it out now. Will give you feedback if that worked! 🙂
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?
> @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 - 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.
@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.

https://community.qualtrics.com/XMcommunity/discussion/comment/16751#Comment_16751This script was not working on a Org Hierarchy question.
How to make the Org Hierarchy question as read only text.


Leave a Reply