is it possible to read a text value of the Form Field Label into jquery variable? | XM Community
Skip to main content

Hello, I have form field question ; and for the email I sent out on submit I need to generate a string “label”+”value”. I can read the value of the input, but I can’t figure out how to read the ‘label”?

 

Hello @nonufrie 

you can manually update the piped text for those options. 

Let’s say that the text entry value piped text for your first field is ${q://QID32/ChoiceTextEntryValue/1}

you just need to replace the part “ChoiceTextEntryValue” for “ChoiceDescription”. So it would be ${q://QID32/ChoiceDescription/1}. 

Hope this helps!


@nonufrie If you want to do it on same page try something like this on change function.

jQuery("#" + this.questionId + ".InputText”).eq(0).val();

Change the eq value based on the field.

Hope it helps!


Hello @nonufrie 

you can manually update the piped text for those options. 

Let’s say that the text entry value piped text for your first field is ${q://QID32/ChoiceTextEntryValue/1}

you just need to replace the part “ChoiceTextEntryValue” for “ChoiceDescription”. So it would be ${q://QID32/ChoiceDescription/1}. 

Hope this helps!

Thank you for you answer. The reason I think I better do it with jquery is that I have so many fields, and I need to concat them only if the input value is not zero(also, it’s not just append values, but I need to add ‘label’ in one <td> cell, and the ‘input’ value in another <td>, and then also where is a <td> with a product of the input value and another Embedded Data. If I do it through workflow the branching looks really long and scary:(


@nonufrie If you want to do it on same page try something like this on change function.

jQuery("#" + this.questionId + ".InputText”).eq(0).val();

Change the eq value based on the field.

Hope it helps!

Hello @Deepak ,
I am trying to implement you suggestion , and I am getting JS error(can’t save),
this is what I have:

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
var temp=jQuery("#" + this.questionId + ".InputText”).eq(0).val();
alert(temp);

});

what do I do miss?
Thank you again.


I think you could do this by getting the inner text of the form fields based on their id, like in the below:

var qid = this.questionId;
var label1 = document.getElementById("QR~"+qid+"~1~label").innerText;
var label2 = document.getElementById("QR~"+qid+"~2~label").innerText;
var label3 = document.getElementById("QR~"+qid+"~3~label").innerText;

You could also do it with jQuery based on the index of span.LabelWrapper label>span, like in the below:

var qid = this.questionId;
var label1 = jQuery("#"+qid+" span.LabelWrapper label>span").eq(0).text();
var label2 = jQuery("#"+qid+" span.LabelWrapper label>span").eq(1).text();
var label3 = jQuery("#"+qid+" span.LabelWrapper label>span").eq(2).text();

 


@Tom_1842 thank you! Your option#2 worked !


Leave a Reply