Hi @JohannesCE,
Can you try enclosing individual variable (Steekwoord 1, 2 etc) in a <span> tag Ex.
<span id=”S1”>Steekwoord 1 : PIPE TEXT</span>
And then through JS hide the id=”S1” if QID1 does not have data i.e., empty.
Hi @SaurabhPujare_Ugam, great tip. However, since that's too many fields to give IDs, I decided that I'd rather have “null” appear after questions that have not been answered. So now the goal is to have appear “null” when a piped text field is empty.
Since all piped text field start with &{ and end with }, I tried this script, but it's not working:
<div id="surveyResults">
<!-- HTML content -->
</div>
<script>
// Function to check and replace empty piped text fields with "null"
function replaceEmptyPipedFields() {
const surveyResults = document.getElementById("surveyResults");
const pipedFields = surveyResults.querySelectorAll("spanAid^='${']");
pipedFields.forEach((field) => {
const text = field.innerText.trim();
if (!text) {
field.innerText = "null";
}
});
}
// Call the function to replace empty piped text fields when the page loads
replaceEmptyPipedFields();
</script>
Any idea why?
Hey @JohannesCE,
Could it be due to when the pipe text is parsed, there will not be any significance of “${“, thus against the span we should have the actual value of the pipe text.
Thus, would it make more sense in the code, if we directly check whether the span contains some value.
Hope I’m making any sense here :)
Hey @JohannesCE,
Could it be due to when the pipe text is parsed, there will not be any significance of “${“, thus against the span we should have the actual value of the pipe text.
Thus, would it make more sense in the code, if we directly check whether the span contains some value.
Hope I’m making any sense here :)
Yes you do! When the email template is parsed and rendered, the ${...}
placeholders for piped text will be replaced with their actual values. As a result, the JavaScript code should directly check whether the span elements contain any value instead of using ${...}
placeholders. This way, it will correctly detect whether the piped text fields are empty or have actual content.
I tried this, but it's still not working:
function hideEmptyElements() {
const variables = r"QID6/ChoiceTextEntryValue", "QID205/ChoiceTextEntryValue"];
variables.forEach(variable => {
const spanElement = document.getElementById(variable);
if (spanElement && !spanElement.textContent.trim()) {
spanElement.style.display = "none";
}
});
}
I'm starting to suspect Qualtrics does not allow JS at all in emails. Could this be? According to one support employee it should work, but nothing I do with JS here as any effect...