Make "Submit" button appear only if people answer "Yes" for a Yes/No question

More
1 year 6 months ago #160957 by FaLifeTime
Hi,

i tried the script and works perfectly. My situation is that i'm trying to only condition the submit button if a particular YES/NO question "shows up". If its hidden or not, with this code it always gonna wait for the user to response the YES/NO question.

Is there a way to only make this code works if the question is visible?

Thanks and excuses me for my english,
4aLifeTime

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

More
1 year 6 months ago #160962 by tpartner
How is the question hidden? By relevance on this page or by something on previous pages?

If on previous pages, this should work:

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initially disable the Next/Submit button
		if($(thisQuestion).is(':visible')) {
			$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
		}
 
		// Listeners on Yes/No radios to toggle the Next/Submit button
		$('input.radio[value="Y"], label[id$="X{QID}Y"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', '').removeClass('ui-state-disabled');
		});
		$('input.radio[value="N"], label[id$="X{QID}N"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
		});
 
    });
</script>

If dynamically on this page, you will need listeners on whatever questions are showing/hiding this question.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: socius, FaLifeTime

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

More
1 year 6 months ago #160983 by FaLifeTime
Exactly what i needed. Thanks a lot!

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

More
1 year 6 months ago #160996 by Joffm
Hi, all,
to be honest, I do not understand this question.

Why should anybody insert a question which offers two answer options, but one without any function?

I think of a scenario like "You have to agree to our terms to proceed...."
In this case people are used to tick a checkbox .

So why not just use a mandatory multiple question with one subquestion.

This should cover everything needed.

Except the challenge for Tony to find a way and develop a new script;)


Maybe somebody can explain to me why this approach with "Yes/No", but without possibility to click "No", was the only way.

Best regards
Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: DenisChenu, socius, LouisGac

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

More
1 year 5 months ago #161958 by socius
Hi all,

thanks to @tpartner for the work and reworks of the script!
I also see your point @Joffm - in the case of a single Y/N I think an error message could suffice.

In my case I have long arrays with lots of statements and agree/disagree scales.
To make answering easier and not frighten my respondents seeing all the lines at once, I would show the array linewise and therefore use subquestion relevance and only show the n+1-th question when the n-th question was answered, etc. This works great with

Question: q1
Subquestions:
sq1 sq_relevance: empty
sq2 sq_relevance: !is_empty(q1_sq1)
sq3 sq_relevance: !is_empty(q1_sq2)
etc.

But: I do not want the "Next" Button to be hidden until the last question of the array was answered. When it unhides/appears it's clear to the respondents that they can continue.

My question is, how your script below (I use LS 2.06LTS) can be reworked to be used for that, i.e. to hide the "Next" Button until the last question of the array was answered (no matter how many questions there are in this array).

Thanks a lot for your help on this!
Best, G


<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initially disable the Next/Submit button
		$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
 
		// Listeners on Yes/No radios to toggle the Next/Submit button
		$('input.radio[value="Y"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', '').removeClass('ui-state-disabled');
		});
		$('input.radio[value="N"]', thisQuestion).click(function(){
			$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
		});
 
    });
</script>

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

More
1 year 5 months ago - 1 year 5 months ago #161964 by tpartner
This will disable the Next/Submit button until all rows in an array are answered.

<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initially disable the Next/Submit button
		$('#movenextbtn, #movesubmitbtn').prop('disabled', 'true').addClass('ui-state-disabled');
 
		// Listeners on radios to enable the Next/Submit button
		$('input.radio', thisQuestion).click(function(){
			if($('input.radio:checked', thisQuestion).length == $('tr.answers-list', thisQuestion).length) {
				$('#movenextbtn, #movesubmitbtn').prop('disabled', '').removeClass('ui-state-disabled');
			}
		});
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 1 year 5 months ago by tpartner.
The following user(s) said Thank You: socius

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

More
1 year 5 months ago #162024 by socius
Thank you Tony! That works perfectly fine!
Best, G

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

More
8 months 2 weeks ago #174840 by Matiasko
I would like to revoke this topic since version 3.0 is here for some time, already. I would like to know how should the code look like right now?

I'm interested in disabling the Submit (or Next) button if:
- Yes option was selected in Yes/No question
- Certain/First option was selected in radio single answer question
- Certain/First option was selected in multiple answer question

Button should be disabled by default or when someone reselects other than the mentioned options.

I really like how the 'disabled' button looks like instead of hiding it, so please keep it that way in code :)

Regards

Matt

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

More
2 months 2 weeks ago #182687 by terryaulenbach
I would also like to know how to make this work with 3.14 for a simple Yes/No question. I have been fighting with it to no avail. I'm not sure what has changed, but I just can't get it to work. Help?

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

More
2 months 2 weeks ago #182689 by tpartner

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

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

More
2 months 2 weeks ago #182694 by terryaulenbach
Thank you as always, Tony. I have been searching and searching for this but that article never materialised for me. I owe you a virtual beer.

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

More
2 months 1 week ago - 2 months 1 week ago #182942 by krosser
I have tried to write a script for such a case, although the Submit button is simply disabled, not hidden.
I would appreciate if you guys can check it out because I am not sure it is bugless.
The code is placed into a radio list type of question with 'yes' and 'no' answer choices, coded as A1 and A2.
<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Initially disable the Next/Submit button
		$('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled');
 
		// Listeners on Yes/No radios to toggle the Next/Submit button
		$('input:radio[value="A1"]', thisQuestion).click(function(){
			$('#ls-button-submit').prop('disabled', '').removeClass('ui-state-disabled');
		});
		$('input:radio[value="A2"]', thisQuestion).click(function(){
			$('#ls-button-submit').prop('disabled', 'true').addClass('ui-state-disabled');
		});
    });
</script>

Thanks in advance! A survey sample attached.

File Attachment:

File Name: limesurvey...4351.lss
File Size:17 KB


PS. Does anyone know why we no longer can select in which language the code is displayed on the forum? It is only gray now.

I'm using the latest LS 3.17 hosted on LS servers, not installed locally.
Attachments:
Last edit: 2 months 1 week ago by tpartner. Reason: Added code language

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

More
2 months 1 week ago #182945 by tpartner
The script looks good.

You can still manually add a language to the code block - I have edited your post accordingly.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

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

More
2 months 1 week ago #182946 by krosser

tpartner wrote: The script looks good.

You can still manually add a language to the code block - I have edited your post accordingly.


Many thanks for checking it out! It is just I have had some strange behavior of conditioned questions not being displayed properly after adding this code. When the survey is active the conditions work, but when it is inactive, then they don't work in the preview.

What should be added to the block, for example, for JS?

I'm using the latest LS 3.17 hosted on LS servers, not installed locally.

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

More
2 months 1 week ago #182947 by DenisChenu
There are no submit button in preview, then the script broke when you try to update an attribute

Add this
if(!$('#ls-button-submit').length != 1) {
return;
}
just before // Identify this question

I don't understand why Expression Manager broke if there are error here … Maybe limesurvey core can do somthing here : EM javascript work with (some) broken JS in question text.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand .
An error happen ? Before make a new topic : remind the Debug mode .

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!