Javascript applying to next page | XM Community
Solved

Javascript applying to next page

  • 8 August 2018
  • 8 replies
  • 116 views

Userlevel 7
Badge +38
Hi everyone. I have a very short 3 question survey. I am distributing by email with the first question embedded as an inline email question. It is the only question on the page (added a page break to the survey editor) between Q1 and Q2. I didn't want respondents to have to click the next button to continue so I tried using Javascript to auto advance to the next page after 1 second. It goes to the next page, however on that screen the Javascript is still trying to advance after 1 second. I don't understand why it is applying here too. The Javascript is only on Q1. A page break separates Q1, then Q2 (display logic applies) and Q3 are on the next page. There is no Javascript on either Q2 or Q3. My survey is published so that shouldn't be a problem. Any ideas are welcome!

The script I applied on Q1 is now attached.
icon

Best answer by TomG 8 August 2018, 18:47

View original

8 replies

Userlevel 7
Badge +33
Can u trying adding another 2_questioa in separate block.
Userlevel 7
Badge +27
Hard to tell without seeing your JavaScript. Maybe you used setInterval instead of setTimeout?
Userlevel 6
Badge +21
Hey @bstrahin ,
Can you share the auto advance code here.
Userlevel 7
Badge +38
Sorry I meant to attach the script and forgot. I added it to my first post. It's code from Princeton's cheat sheet. Attached again.
Userlevel 7
Badge +38
@bansalpeeyush29 thank you for your idea. I tried moving Q2 and Q3 to their own block (still no Javascirpt on those questions or blocks) and it is auto advancing in Chrome.
Userlevel 7
Badge +27
PeriodicalExecuter is the same as setInterval. Use setTimeout instead:
```
setTimeout(function () {jQuery('#NextButton').click();},1000);
```
Userlevel 6
Badge +21
> @TomG said:
> PeriodicalExecuter is the same as setInterval. Use setTimeout instead:
> ```
> setTimeout(function () {jQuery('#NextButton').click();},1000);
> ```

Great @TomG 😀

@bstrahin,
function used by you will execute periodically.
check below link:
http://api.prototypejs.org/language/PeriodicalExecuter/
Userlevel 7
Badge +38
@TomG, @PradeepKotian, and @bansalpeeyush29 thank you for your quick responses! Working like a charm now. And @PradeepKotian thank you for the extra resources. I'm not a coder and try to recycle publically available code, but obviously do not have a deep understanding when things go wrong. It's great having experts like you to help us noncoders out!

Leave a Reply