How can I strip the first 7-8 characters of a text entry off of the response? | XM Community
Skip to main content

  1. If I have the respondent enter a URL and it includes the https:// or http:// (as many will type or copy/paste) when I try to share that response via a trigger or action email, Qualtrics adds PROXY text to it. Not only does this make it unruly, but from time to time, browsers try hard to reject this link. Also, if I want to include it on a brochure it is unsightly and unecessary.

  2. If I use the URL without the precedent - it is fully accessible as a link, so the https:// or http:// is unecessary

  3. SO...any idea about how to remove the precedent from the entered data? I can put two strings together but I don't seem able to remove part of a string.

You could remove it with JavaScript in the addOnPageSubmit function on the question where you collect it. For example:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var input = jQuery("#"+this.questionId+" .InputText");
input.val(input.val().replace(/^https?:\\/\\//i,""));
});


I'll test that out! It would be a great help. Since you made that look so easy, is there a way to replace http:// also? Since they may use either?


That didn't work...possibly because I didn't replace something in your code with a value I was supposed to? Here's what I put in the question's JS section.

Qualtrics.SurveyEngine.addOnload(function()
{
jQuery("#"+this.question+" .InputText").replace(/^https?:\\/\\//i,"");
});

Was I supposed to replace "#" with a value? Or "InputText"?


https://www.qualtrics.com/community/discussion/comment/29544#Comment_29544Sorry, the original code I posted had a mistake. I've corrected it in the original post above. Use as-is (don't change anything) - it works for http:// or https://
Add to the addPageOnSubmit() function - NOT addOnload().


I really appreciate your help...but, there is no "addPageOnSubmit() function. This is what I see. The first three are there by default. I tried adding the fourth...
Qualtrics.SurveyEngine.addOnload(function()
{
});
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*/
});
Qualtrics.SurveyEngine.addOnPageSubmit(function()
var input = jQuery("#"+this.questionId+" .InputText");
input.val(input.val().replace(/^https?:\\/\\//i,""));

I get an invalid token or Var


https://www.qualtrics.com/community/discussion/comment/29547#Comment_29547It is addOnPageSubmit(). I updated the original post above with the whole thing.


TomG I owe you a lunch! Thanks, that did the trick. And for anyone following along, I removed all of the default JS in the Question and replaced it with Tom's code:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var input = jQuery("#"+this.questionId+" .InputText");
input.val(input.val().replace(/^https?:\\/\\//i,""));
});
I tested with https://, http://, and finally with neither and it worked like a charm! Thanks again. I'm going to post in another thread where someone was trying to find an answer.


Leave a Reply