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

Can i add a display logic to header using javascript?

  • 11 May 2018
  • 3 replies
  • 121 views

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!
icon

Best answer by TomG 14 May 2018, 22:28

View original

3 replies

Userlevel 7
Badge +27
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.
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>
Userlevel 7
Badge +27
@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();
```

Leave a Reply