Randomizing Problem with onclick JS Event

More
3 years 5 months ago #122499 by yasm
yasm created the topic: Randomizing Problem with onclick JS Event
Hi!

I have a survey (Version 2.05+ Build 131209) with two question groups. In the first group there is 6 questions:
1x Equation Type
5x Text Display Type (in each one there is a link to open a popup window)
The Principe is to randomise the show one of the 5 Display text question versions to the users.
So I structured the group as follows:
  • In the Equation – Question Type (Code= randnr):
    If (randnr >= 1, randnr, (rand(1, 5)))
  • And in the five Text Display – Questions type:
    <p>Please click on the following link to see the Gallery</p>
    <h3 style="color: red; text-align: center;">
    	<span style="font-size:28px;">
    	<a href="http://mylink.com/gallery_1" onclick="window.open(this.href, '', 'resizable=no,status=no,location=no,toolbar=no,menubar=no,fullscreen=no,scrollbars=no,dependent=no,width=1024,height=800'); return false;">► GALLERY ◄</a></span></h3>
    And in the appropriate relevance was : (randnr.NAOK == "1"))
    and for the second question : (randnr.NAOK == "2"))
    etc. ….
Until now the randomizing works perfectly!

But I want that the PopUp window to close after 9 seconds, so I tried to change the Text Display Question and add a JScript code as follows:
<script type="text/javascript" language="JavaScript">
  function openwindow() {
  win = window.open("http://mylink.com/gallery_1","my_new_window","width=1024,height=800,top=0,left=0");
  window.setTimeout("win.close()", 9000);
  }
</script>
<p>Please click on the following link to see the Gallery</p>
<h3 style="color: red; text-align: center;">
	<span style="font-size:28px;">
	<a href="#" onclick="javascript:openwindow();">► GALLERY ◄</a></span></h3>
And the appropriate relevance wasn’t changed.

After the changes the randomizing no longer works correctly.

Did I do something wrong? Did call the survey the rand()-function twice?
Thanks for the Help.

Yasmina.

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #122500 by gabrieljenik
gabrieljenik replied the topic: Randomizing Problem with onclick JS Event
Hi !

You are likely to have a JS bug.
Please, open the console window to check for any JS errors.

As from what I see you may have a JS error when it says:
window.setTimeout("win.close()", 9000);
Maybe it should say:
window.setTimeout(function(){win.close()}, 9000);

Try replacing the code and also reviewing for JS errors in the console.

Cheers,

Gabriel

Cheers,
Gabriel - www.Encuesta.Biz - Authorized Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?)....[img]

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #122502 by tammo
tammo replied the topic: Randomizing Problem with onclick JS Event
You are using a version of LimeSurvey that was released in december 2013. When possible, I would upgrade to the most recent 2.05+ version. I would not use 2.06 for production yet, there seem to be several errors in that version still.

Tammo


Tammo ter Hark at Tools for Research
Proud developers of the TFR Responsive Limesurvey template
toolsforresearch.com/limesurvey-responsive-template

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!