Can i add a display logic to header using javascript? | XM Community
Skip to main content
Solved

Can i add a display logic to header using javascript?

  • May 11, 2018
  • 3 replies
  • 220 views

Piotr
Hi, I was wondering if there is any way I can hide header in some part of the questionnaire using java script or other functionality? I am talking about the look and feel header. I would like this header to be displayed for example after some question or section. Would much appreciate any answer or clue. Thanks!

Best answer by TomG

@Piotr, You have a couple of syntax errors plus (1==1 isn't a valid assignment and your ending semi-colon needs to be inside the }. Also, your code will throw an error is QR~QID939~1 isn't on the page. It isn't clear to me if you want to display the header on the same page when the question is answered (in which you you need an event listener on the input) and/or on the subsequent pages (in which case you need to pipe the answer to the script). Anyway, start your script by hiding the header, then show it if some condition is met: ``` jQuery("#Header").hide(); if( some condition ) jQuery("#Header").show(); ```

3 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • May 11, 2018
Yes, you can hide the header with JavaScript: ``` jQuery("#Header").hide(); ``` The JavaScript can be in the header itself (inside a script tag) or attached to a question on the page. P.S. You posted your question twice.

Piotr
  • Author
  • 6 replies
  • May 13, 2018
Thanks Tom, so now I am trying to use your script with if statement, so the header is displayed after specific question is answered. I am using the code below, however header is visible from the beginning. Could you advise what i should change to make it work? <quote>Qualtrics.SurveyEngine.addOnload(function() { if ($("QR~QID939~1").value > 0) {1==1} else {jQuery("#Header").hide()}; }); </quote>

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • Answer
  • May 14, 2018
@Piotr, You have a couple of syntax errors plus (1==1 isn't a valid assignment and your ending semi-colon needs to be inside the }. Also, your code will throw an error is QR~QID939~1 isn't on the page. It isn't clear to me if you want to display the header on the same page when the question is answered (in which you you need an event listener on the input) and/or on the subsequent pages (in which case you need to pipe the answer to the script). Anyway, start your script by hiding the header, then show it if some condition is met: ``` jQuery("#Header").hide(); if( some condition ) jQuery("#Header").show(); ```