Position of error message on page | XM Community
Skip to main content
Solved

Position of error message on page


Forum|alt.badge.img+6
  • Level 2 ●●
  • 19 replies

Hello, I have a custom coded error message that appears if a participant's response is not correct. My code, based on other forum responses works perfectly. However, the error message gets inserted below the next button at the bottom of the page. I want to move the error message to closer to the question (above the Next button). Is there a way to modify my code to be able to do that? Current code below..

if (res == correct) {
  jQuery('#NextButton').click();
  jQuery('#CustomNextButton').hide();
} else {

  /* This is where you set your error message text */
  var errorMsg = "Please enter the correct code";
  var x = document.createElement("DIV");
  var t = document.createTextNode(errorMsg);
  x.className = "custom-warning";
  x.appendChild(t);
  document.getElementById('Questions').parentElement.appendChild(x);
jQuery('.custom-warning').css("background", "pink");
jQuery('.custom-warning').css("color", "red");
jQuery('.custom-warning').css("font-size", "12px");


}
});

Best answer by TomG

Remove ".parentElement" from this line:
document.getElementById('Questions').parentElement.appendChild(x);

View original

2 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5940 replies
  • Answer
  • April 15, 2020

Remove ".parentElement" from this line:
document.getElementById('Questions').parentElement.appendChild(x);


Forum|alt.badge.img+6
  • Author
  • Level 2 ●●
  • 19 replies
  • April 15, 2020

Awesome! thanks so much! perfectly placed now.


Leave a Reply