Prevent Pasting in Answers | XM Community
Skip to main content
Question

Prevent Pasting in Answers


Forum|alt.badge.img+2

Hi all,

Does anyone have a javascript to prevent participants from being able to paste in answers to text boxes? We’ve had a lot of participants who copy something from another website and just paste it in our survey text box, so I was hoping preventing pasting might discourage this. Thanks!

4 replies

ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • June 4, 2023

Try this in addOnload() function.

 

jQuery('Input:textbox').on("cut copy paste",function(e) {
      e.preventDefault();
   });

 You can replace Input:textbox with OE box #id if it will not work.


Forum|alt.badge.img+2
  • Author
  • Level 1 ●
  • 1 reply
  • June 6, 2023

Thanks so much @ArunDubey, unfortunately it’s still not working for me but I really appreciate the help!


ArunDubey
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+41
  • QPN Level 8 ●●●●●●●●
  • 589 replies
  • June 6, 2023
carubie wrote:

Thanks so much @ArunDubey, unfortunately it’s still not working for me but I really appreciate the help!

jQuery('textarea').on("cut copy paste",function(e) {
      e.preventDefault();
	jQuery(".ValidationError").eq(0).text("Please enter the value, you are not allowed to paste value here.").addClass("error-msg").show();
   });

It should work. anyways I have updated the selector a ‘textarea’, and add one error message too. try this. you can change or remove error message if it is not required.

 

Please note: simple layout didn’t support JS. if you are using simple layout then you cannot use any custom functionality.


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • 876 replies
  • June 6, 2023

Simple layout does support JavaScript, but jQuery needs to be loaded and selectors are a bit different. If using Simple layout, first add the below to the survey’s header:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Then, add the below to the Text Entry question’s JavaScript in the OnReady section:

jQuery("#question-"+this.questionId+" .text-input").on("cut copy paste",function(e) {
      e.preventDefault();
   });

If using Flat, Modern, or Classic layouts, add the below to the Text Entry question’s JavaScript in the OnReady section:

jQuery("#"+this.questionId+" .InputText").on("cut copy paste",function(e) {
      e.preventDefault();
   });