Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

THEMA: Hiding multiple choice with comments text box and more

Hiding multiple choice with comments text box and more 1 Monat 4 Wochen her #105317

  • AGK925
  • AGK925s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 2
  • Karma: 0
Hello,

I am new to LimeSurvey and fairly new to Java. I am attempting to use the code above for a survey and I am running into some trouble.

I would like to hide the first three comment boxes and check that the remaining comments are filled in when the corresponding multiple choice is selected. I do not need to pipe in the text responses to another question. Below is the code I am attempting to use to accomplish my tasks.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() { 
 
		var q1ID = 68;
		var msg = 'Please specify in the comment box.';
 
		// Hide the first 3 text inputs of Q1
		$('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide();
		$('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide();
		$('#question'+q1ID+' li[id^="javatbd"]:eq(2) .comment').hide();
 
		// Interrupt next/submit function 
		$('#movenextbtn, #movesubmitbtn').click(function(){
 
			// Reset some stuff
			var failedMandatory = 0;
			$('#question'+q1ID+' input.text').css({'background':''});;
 
			// Loop through all check answers in Q1
			$('#question'+q1ID+' input.checkbox:checked').each(function(i){
 
				// Define the row
				var thisRow = $(this).parents('li:eq(0)');
 
				// Check for empty mandatory text inputs
				if($('input.text:visible', thisRow).length > 0 && $('input.text', thisRow).val() == '') {
					$('input.text', thisRow).css({'background':'pink'});
					failedMandatory = 1;
				}
			});	
 
			// Abort submit if any mandatory text inputs are empty
			if(failedMandatory == 1) {
				alert (msg);
				return false;	
			}
			else {
				return true;	
			}
		});
	});
 
</script>

If I just use the first part that hides the text inputs it works fine. However, when I include everything from "// Interrupt next/submit function" down it does not work, and the text inputs are no longer hidden.

Any help would be greatly appreciated.

Tony
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Hiding multiple choice with comments text box and more 1 Monat 4 Wochen her #105351

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5279
  • Dank erhalten: 289
  • Karma: 246
Please post a link to an activated test survey.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Hiding multiple choice with comments text box and more 1 Monat 4 Wochen her #105363

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 3813
  • Dank erhalten: 683
  • Karma: 328
Since the inclusion of Expression Manager we need to have a space or line-break after all opening curly braces and before all closing curly braces. (don't get me started on the whole "valid JavaScript" discussion again)

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() { 
 
		var q1ID = 68;
		var msg = 'Please specify in the comment box.';
 
		// Hide the first 3 text inputs of Q1
		$('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide();
		$('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide();
		$('#question'+q1ID+' li[id^="javatbd"]:eq(2) .comment').hide();
 
		// Interrupt next/submit function 
		$('#movenextbtn, #movesubmitbtn').click(function(){
 
			// Reset some stuff
			var failedMandatory = 0;
			$('#question'+q1ID+' input.text').css({ 
				'background':'' 
			});
 
			// Loop through all check answers in Q1
			$('#question'+q1ID+' input.checkbox:checked').each(function(i){
 
				// Define the row
				var thisRow = $(this).parents('li:eq(0)');
 
				// Check for empty mandatory text inputs
				if($('input.text:visible', thisRow).length > 0 && $('input.text', thisRow).val() == '') {
					$('input.text', thisRow).css({
						'background':'pink'
					});
					failedMandatory = 1;
				}
			});	
 
			// Abort submit if any mandatory text inputs are empty
			if(failedMandatory == 1) {
				alert (msg);
				return false;	
			}
			else {
				return true;	
			}
		});
	});
 
</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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: AGK925

Hiding multiple choice with comments text box and more 1 Monat 4 Wochen her #105402

  • AGK925
  • AGK925s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 2
  • Karma: 0
Thank you very much for your help. It works brilliantly, I spent a lot of time looking for solutions but apparently missed out on the basics of writing the scripts within a question. Now that I have gotten past this hurdle I think it would be wise to spend time learning the basics.

Again thank you very much for your help. This was my first attempt to use LimeSurvey and it seems like it is a great tool for creating online surveys with a wonderfully helpful community.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.148 Sekunden
Donation Image