Block Copy Paste in a text entry box | XM Community
Skip to main content

I have two text entry boxes on a survey that are meant for employee ID. Both have custom validation. The first one limits entry to a specific number of numeric digits only. The second one serves to match against the first one.

I would like to prevent someone from copying the value from the first one (in case it is incorrect) and pasting it into the second one.

For this I guess you are using text entry form type question with two fields.
Paste the below code in the JS of this question:
jQuery("#"+this.questionId+" .InputText:eq(1)").on("cut copy paste",function(e) {
   e.preventDefault();
  });


Thanks. I must be doing something wrong. I know nothing about Java Script. This is what I see when I go to the JS portion for the field. Do I replace the entire thing with your line of code? Or?

Qualtrics.SurveyEngine.addOnload(function()
{
 /*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function()
{
 /*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
 /*Place your JavaScript here to run when the page is unloaded*/
});


It will be under onReady function as shown below:
image.png


This is what I have. Upon testing in preview mode and through a link, I can still copy/paste. I tried putting it in the JS for each of the two questions thinking that might work, but it didn't.


2020-05-14_20-05-03.png


Which question type are you using?



The custom validation is Matches RegEx to make it so that the user can only enter seven numerical digits.
2020-05-15_6-11-05.png


Try the below code:
jQuery("#"+this.questionId+" .InputText:eq(0)").on("cut copy paste",function(e) {
   e.preventDefault();
  });


Works perfectly. Thanks


Leave a Reply