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

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",getUsernamea0]); 

});

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

Thanks!
Erin

@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",getUsernamee0]);

});

 


This did the trick! Thank you, @Deepak!

 

-Erin 


@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 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.


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


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 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.


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!


Leave a Reply