Welcome, Guest
Username: Password: Remember me

TOPIC: javascript automatic yes/no fails after update

javascript automatic yes/no fails after update 3 years 4 months ago #63465

  • claudio123
  • claudio123's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Today I made the update to LimeSurvey Version 1.91+ Build 10494 and since then have problems with questions including javascript that allow to show/hide other questions based on yes/no. attached you can find a sample survey that explains what I mean.
The auto-fill of yes/no does not seem to work any more.

Thanks for having a look.

Best regards
Claudio

File Attachment:

File Name: limesurvey_survey_38565.lss
File Size: 51 KB
... lost in brackets ...
(I suggest a preview option for posting in the forum)
The administrator has disabled public write access.

Re: javascript automatic yes/no fails after update 3 years 4 months ago #63467

  • holch
  • holch's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 2957
  • Thank you received: 380
  • Karma: 124
decide001 opens up Q004 if response is yes without a problem here.

I use Version 1.91+ Build 10377

Upgraded to Version 1.91+ Build 10494 just to make sure and works as well.

Seems like there has gone something wrong during the upgrade. From which version did you upgrade?
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
Last Edit: 3 years 4 months ago by holch.
The administrator has disabled public write access.

Re: javascript automatic yes/no fails after update 3 years 4 months ago #63468

  • claudio123
  • claudio123's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Thanks holch,

06/24/2011 was the day I did the update, I did not write down the sub-version before I did the update.

The problem is a bit more complex:

decide001 should switch to yes or no automatically, as soon as at least 4 subquestions to Q003 are answered "for sure". This is done with a ascript based on work done by Tony Partner, it does however require the source in the help of "decide001" be adjusted to the right question ID`s. In my case it's like written there:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Call the function
		// Params - Q3 ID, Q4 ID, Hidden question ID, number to be checked
		countChecked(254, 255, 257, 4);
....

in the last line above the numbers are the question IDs, 254 is the question ID of tzhe array of q003, 255 is q004, 257 is the ID of this yes/no question and 4 is the number of minimum occurrences to switch to yes.

it worked flawlessly until I did the update, the question ID's also did not change.

Edit: If I manually switch decide001 to yes or no the following question is shown/hidden as it should. I want it to switch automatically (like it did before).


Thanks + best regards
Claudio
... lost in brackets ...
(I suggest a preview option for posting in the forum)
Last Edit: 3 years 4 months ago by claudio123. Reason: added edit
The administrator has disabled public write access.

Re: javascript automatic yes/no fails after update 3 years 4 months ago #63470

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4367
  • Thank you received: 828
  • Karma: 381
I don't know why you have any reference to q004 in that script. q004 is show/hidden by conditions when decide001 is toggled by the script.

This works fine, assuming 254 = q003 ID and 257 = decide001 ID.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Call the function
		// Params - Q3 ID, Hidden question ID, number to be checked
		countChecked(254, 257, 4);
 
		function countChecked(q1ID, qHiddenID, maxChecked) {
 
			// Find the survey and group IDs
			if($( 'input#fieldnames' ).length != 0) {
				var fieldNames = $( 'input#fieldnames' ).attr('value');
				var tmp = fieldNames.split('X');
				var sID = tmp[0];
				var gID = tmp[1];
			}
 
			// Hide the hidden question
			// $('#question'+qHiddenID+'').hide();
 
			// Add a class to the last answer cell in each row of Q3
			$('#question'+q1ID+' table.question tbody tr').each(function(i) {
				$('td:last', this).addClass('lastCell');
			});
 
			// A listener on the answer cells in Q3
			$('#question'+q1ID+' table.question tbody tr td').click(function() {
 
				// A small delay to allow the radio to be checked
				setTimeout(function() {
 
					// Toggle qHidden depending on how many "lastCell" radios are checked
					if($('.lastCell input.radio:checked').length >= maxChecked) {
						$('#question'+qHiddenID+' input.radio[value="Y"]').attr('checked', true);
						var hiddenInputValue = 'Y';
					}
					else {
						$('#question'+qHiddenID+' input.radio[value="N"]').attr('checked', true);
						var hiddenInputValue = 'N';
					}
 
					// Fire the conditions function to show/hide Q4s					
					var hiddenInputName = $('#question'+qHiddenID+' input.radio[value="Y"]').attr('name');
					var hiddenInputType = 'radio';
					checkconditions(hiddenInputValue, hiddenInputName, hiddenInputType);
 
				}, 500); 
			});
		}
 
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: javascript automatic yes/no fails after update 3 years 4 months ago #63471

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
The underlying problem is a bug introduced when fixing issue #5319. After that fix (revision 10425)JavaScript in Help text could no longer get into the generated .html file.

I'll create the bug ticket and patch it.

There may be other issues too, but if you look at the generated .html code, you'll see that your Javascript countChecked() function is no where to be found.
The administrator has disabled public write access.
The following user(s) said Thank You: claudio123

Re: javascript automatic yes/no fails after update 3 years 4 months ago #63476

  • claudio123
  • claudio123's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Thanks Tom,

I checked the html with firebug and was surprised to see no countChecked() function, yes.
Now I tried the script in the question's source (not in the help) and voilá: it works.

Thanks Tom,
best wishes
Claudio
... lost in brackets ...
(I suggest a preview option for posting in the forum)
The administrator has disabled public write access.

Re: javascript automatic yes/no fails after update 3 years 4 months ago #63481

  • claudio123
  • claudio123's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Tony,

q004 is not needed in the script, yes. The problem is elsewhere as Tom made clear - the script works as it should when written in the question source but refuses to work when in the help source. This is what became clear and what will all likely effect other scripts that are written in the help source until an update is released with a bugfix.
It's not your bug :-) - your script works just fine.

Thanks, best wishes
Claudio
... lost in brackets ...
(I suggest a preview option for posting in the forum)
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.135 seconds
Donation Image