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 2 Jahre 8 Monate her #70804

  • uxexp
  • uxexps Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 19
  • Karma: 0
Hello,
I am using a multiple choice with comments question type. Some of the choices do not require further comments while other do. Can I hide the comments box next to the choices that do not require comments. For exmple:

Q: Choose the websites you have visited in the past:

1. Facebook (no comments)
2. Google (no comments)
3. A work related website [please specify in the comment box]
4. An entertainment website [please specify in the comment box]

Also, is it possible to make the comment piece mandatory for answer choices 3 and 4 (only if selected) in the above example?

Lastly, I would like to capture the first 2 checked labels from the above choices in two separate hidden short text boxes to ask follow-up questions. So for example, if the user chose Google and listed Yahoo Finance for work related website I would like to populate the two short text boxes with "Google" and "Yahoo Finance".

Appreciate your help!

Thanks.
Letzte Änderung: 2 Jahre 8 Monate her von uxexp.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hiding multiple choice with comments text box and more 2 Jahre 8 Monate her #70818

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4139
  • Dank erhalten: 767
  • Karma: 348
I assume that the "two separate hidden short text boxes" are in a multiple-text question.

Lets call the multiple-options-with-comments question Q1 and the multiple-text question Q2

If Q1 and Q2 are on the same page, you can do this:

1) Set up your survey to use JavaScript.

2) Add the following script to the source of one of the questions. Replace "11" with the Q1 question ID and "22" with the Q2 question ID.

The script does the following:
- Hides the first two text inputs in Q1
- Makes the visible comments mandatory if their associated box is checked
- Loads the text of the first two checked options in Q1 into the text inputs of Q2 (if the option has a visible comment, that is loaded instead)
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() { 
 
		var q1ID = 11;
		var q2ID = 22;
		var msg = 'Please specify in the comment box.';
 
		// Hide the first 2 text inputs of Q1
		$('#question'+q1ID+' li[id^="javatbd"]:eq(0) .comment').hide();
		$('#question'+q1ID+' li[id^="javatbd"]:eq(1) .comment').hide();
 
		// Interrupt next/submit function 
		$('#movenextbtn, #movesubmitbtn').click(function(){
 
			// Reset some stuff
			var failedMandatory = 0;
			$('#question'+q1ID+' input.text').css({'background':''});
			$('#question'+q2ID+' input.text').val('');
 
			// 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;
				}
 
				// Load the multiple-text question
				if($('input.text:visible', thisRow).length > 0) {
					$('#question'+q2ID+' input.text:eq('+i+')').val($('input.text', thisRow).val());
				}
				else {
					$('#question'+q2ID+' input.text:eq('+i+')').val($.trim($(this).parent().text()));
				}
			});	
 
			// 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.
Letzte Änderung: 2 Jahre 8 Monate her von tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hiding multiple choice with comments text box and more 2 Jahre 8 Monate her #70828

  • uxexp
  • uxexps Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 19
  • Karma: 0
SIMPLY WONDERFUL!!

On a different note: would recommend a book on JavaScript for beginners?
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hiding multiple choice with comments text box and more 2 Jahre 8 Monate her #70833

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4139
  • Dank erhalten: 767
  • Karma: 348
Hmm...it's been a while...

You'll probably want something on jQuery too - have a look at these:

1) www.peachpit.com/store/product.aspx?isbn=0321772970

2) www.peachpit.com/store/product.aspx?isbn=0321647491
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.

Re: Hiding multiple choice with comments text box and more 2 Jahre 8 Monate her #70894

  • uxexp
  • uxexps Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 19
  • Karma: 0
Thanks much Tony!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hiding multiple choice with comments text box and more 2 Jahre 6 Monate her #74208

  • tomdelf
  • tomdelfs Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 3
  • Karma: 0
Hi,

this was exactly what i was looking for, but i'm having problems with the second part, ie. if the checkbox is checked, the comment box is mandatory.

It doesn't work for me and i have no idea why ;) I can just simply submit answers without comment boxes being mandatory, i get no alert messages.

Any clues where to start looking?

Cheers,

Tom
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hiding multiple choice with comments text box and more 2 Jahre 6 Monate her #74209

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5324
  • Dank erhalten: 294
  • Karma: 249
Please post a link to a simple test survey containing the adapted code.

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.

Re: Hiding multiple choice with comments text box and more 2 Jahre 6 Monate her #74242

  • tomdelf
  • tomdelfs Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 3
  • Karma: 0
Sorry, false alarm... seems to work now!

Many thanks in any case for your prompt response!

Tom
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Hiding multiple choice with comments text box and more 2 Jahre 6 Monate her #74247

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5324
  • Dank erhalten: 294
  • Karma: 249
tomdelf schrieb:
Sorry, false alarm... seems to work now!

Many thanks in any case for your prompt response!

Tom
You're welcome :-)

If our hints have been helpful and you enjoy limesurvey please consider a donation to the team .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.

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.

Re: Hiding multiple choice with comments text box and more 1 Jahr 3 Monate her #96163

  • benmok
  • benmoks Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 10
  • Karma: 0
Hi - How do you make it the text box only appear for those that the respondent select in the check box?

Thanks,
Ben
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.182 Sekunden
Donation Image