Home arrow Ondersteuning arrow Forums
LimeSurvey Forums
Welcome, Guest
Please Login or Register.    Lost Password?
[done] checkconditions() is executed twice (1 viewing) (1) Guest
Go to bottom Favoured: 0
TOPIC: [done] checkconditions() is executed twice
#19372
ls2312 (User)
Fresh Lemon
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
[done] checkconditions() is executed twice 1 Month, 3 Weeks ago Karma: 0  
Hi all,

I placed some custom code within the checkconditions() function. checkconditions is called by default using the onclick event from the radiobuttons of a yes-no-uncertain matrix.
For some reason the onclick event is fired twice each time a user makes a selection.

Any thoughts what the problem is caused by and how to correct it?

Thanks,
ls2312
 
Logged Logged  
 
Last Edit: 2008/09/30 10:38 By Mazi.
  The administrator has disabled public write access.
#19430
jcleeland (Admin)
Moderator Lime
Posts: 243
graphgraph
User Offline Click here to see the profile of this user
Re:checkconditions() is executed twice 1 Month, 3 Weeks ago Karma: 7  
Hi, I can have a quick look as to why checkconditions is happening twice.. maybe you could upload the survey so I can be testing on the same survey as you?

Are you displaying group-by-group?

Jason
 
Logged Logged  
  The administrator has disabled public write access.
#19439
jcleeland (Admin)
Moderator Lime
Posts: 243
graphgraph
User Offline Click here to see the profile of this user
Re:checkconditions() is executed twice 1 Month, 3 Weeks ago Karma: 7  
Actually, no need.. I can get it happening myself. Why, I don't know though. It's definitely only called once.
 
Logged Logged  
  The administrator has disabled public write access.
#19443
jcleeland (Admin)
Moderator Lime
Posts: 243
graphgraph
User Offline Click here to see the profile of this user
Re:checkconditions() is executed twice 1 Month, 3 Weeks ago Karma: 7  
Well, I've put the actual "why" of it into the "stupid javascript" basket, because I don't know why it would do that. I think it has something to do with using onClick in a radio group.. but I can't get anymore information on that issue. So, rather than worry about why, instead I've looked for a "how to stop it".

I don't think this is a bug per-se, so I don't want to modify the source - however if you want to stop the javascript function occurring twice, you need to edit your group.php file, and maybe your survey.php file:

look for the line:
function checkconditions(value, name, type)

and insert a new line before this line that says:
var count=0;

then insert two new lines after that line that say:
count++;
if(count > 1) {count = 0; exit;}

That should stop the function from executing more than once per time.. I hope!

Let me know how you go.

My whole change ends up looking like this:

print <<<END
var count=0;
function checkconditions(value, name, type)
{
count++;
if(count > 1) {count = 0; exit;}
END;


Jason
 
Logged Logged  
  The administrator has disabled public write access.
#19451
ls2312 (User)
Fresh Lemon
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
Re:checkconditions() is executed twice 1 Month, 3 Weeks ago Karma: 0  
Thank you for investigating. What I want to do is to count how many yes's and no's a user has checked because out of x answers everybody is only allowed n-times yes and m-times no. The way I did it was to modify checkconditions as it is already called when onclick occurs.
My program-logic works except that it is called twice per click which results in bad behavior when the n-th or m-th click is performed. I store the IDs of the answers in two arrays (one for yes and one for no) and update them on each click.
Is there any better place to put this functionality?
BTW I am using Limesurvey Version 1.71+ (5638).

The bad hack, err workaround would be to alternate a variable and use it to ignore each second call. But as soon as the problem is fixed or a browser doesn't show this behavior everything is broken again because then every second click is not counted...
 
Logged Logged  
  The administrator has disabled public write access.
Go to top