How to parse first part of entered email address and save as a new embedded data element | XM Community
Skip to main content
Solved

How to parse first part of entered email address and save as a new embedded data element

  • July 12, 2023
  • 8 replies
  • 128 views

JonesE
Level 4 ●●●●
Forum|alt.badge.img+26
  • Level 4 ●●●●
  • 65 replies

I have participants entering their email address in a text field on a single page survey. I want to take the part that appears before the @ in the email address and assign it to a new embedded data variable.

For example, if I entered jonese@ email.com (extra space added after the @ to avoid linking to a fake email) in the text field, I would want to assign the string “jonese” to the embedded variable.

Here’s the code I have that isn’t working:

 

Qualtrics.SurveyEngine.addOnUnload(function()

{

    /*Place your JavaScript here to run when the page is unloaded*/

    

    var kkiEmail = "${q://QID12/ChoiceTextEntryValue}";  

    var getUsername = kkiEmail.split("@"); 

    Qualtrics.SurveyEngine.setEmbeddedData("username",getUsername[0]); 

});

Any suggested JavaScript syntax and guidance on where it should be placed would be greatly appreciated!

Thanks!
Erin

Best answer by Deepak

@JonesE Try this

Qualtrics.SurveyEngine.addOnPageSubmit(function()

{

/*Place your JavaScript here to run when the page is unloaded*/

var kkiEmail = jQuery('[id="QR~QID12"]').val();

var getUsername = kkiEmail.split("@");

Qualtrics.SurveyEngine.setEmbeddedData("username",getUsername[0]);

});

 

8 replies

Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • 1555 replies
  • Answer
  • July 12, 2023

@JonesE Try this

Qualtrics.SurveyEngine.addOnPageSubmit(function()

{

/*Place your JavaScript here to run when the page is unloaded*/

var kkiEmail = jQuery('[id="QR~QID12"]').val();

var getUsername = kkiEmail.split("@");

Qualtrics.SurveyEngine.setEmbeddedData("username",getUsername[0]);

});

 


JonesE
Level 4 ●●●●
Forum|alt.badge.img+26
  • Author
  • Level 4 ●●●●
  • 65 replies
  • July 12, 2023

This did the trick! Thank you, @Deepak!

 

-Erin 


JonesE
Level 4 ●●●●
Forum|alt.badge.img+26
  • Author
  • Level 4 ●●●●
  • 65 replies
  • July 14, 2023

@Deepak So for reasons I do not understand, this worked once and has failed ever since. Nothing else about the code or question was tweaked. Any reason why that might happen?


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • 1555 replies
  • July 17, 2023

@Deepak So for reasons I do not understand, this worked once and has failed ever since. Nothing else about the code or question was tweaked. Any reason why that might happen?

Have you changed the question as this might change question id.


Forum|alt.badge.img+9
  • Level 5 ●●●●●
  • 42 replies
  • July 17, 2023

I used the same code, and it is working fine.


JonesE
Level 4 ●●●●
Forum|alt.badge.img+26
  • Author
  • Level 4 ●●●●
  • 65 replies
  • July 18, 2023

I used the same code, and it is working fine.

Did you run more than one response with this code? It worked for one response, but for no other responses after that.


Forum|alt.badge.img+9
  • Level 5 ●●●●●
  • 42 replies
  • July 18, 2023

I used the same code, and it is working fine.

Did you run more than one response with this code? It worked for one response, but for no other responses after that.

I did that for multiple responses, and it worked like a charm.


JonesE
Level 4 ●●●●
Forum|alt.badge.img+26
  • Author
  • Level 4 ●●●●
  • 65 replies
  • July 18, 2023

I used the same code, and it is working fine.

Did you run more than one response with this code? It worked for one response, but for no other responses after that.

I did that for multiple responses, and it worked like a charm.

Weird. I’m not sure why it stopped working on my end, but hopefully this ends up being helpful for others!