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

More
11 months 4 weeks ago #160957 by FaLifeTime
FaLifeTime replied the topic: Make "Submit" button appear only if people answer "Yes" for
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
11 months 4 weeks ago #160962 by tpartner
tpartner replied the topic: Make "Submit" button appear only if people answer "Yes" for
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.
The following user(s) said Thank You: socius, FaLifeTime

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

More
11 months 3 weeks ago #160983 by FaLifeTime
FaLifeTime replied the topic: Make "Submit" button appear only if people answer "Yes" for
Exactly what i needed. Thanks a lot!

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

More
11 months 3 weeks ago #160996 by Joffm
Joffm replied the topic: Make "Submit" button appear only if people answer "Yes" for
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
10 months 4 weeks ago #161958 by socius
socius replied the topic: Make "Submit" button appear only if people answer "Yes" for
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
10 months 4 weeks ago - 10 months 3 weeks ago #161964 by tpartner
tpartner replied the topic: Make "Submit" button appear only if people answer "Yes" for
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.
Last Edit: 10 months 3 weeks ago by tpartner.
The following user(s) said Thank You: socius

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

More
10 months 3 weeks ago #162024 by socius
socius replied the topic: Make "Submit" button appear only if people answer "Yes" for
Thank you Tony! That works perfectly fine!
Best, G

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

More
1 month 2 weeks ago #174840 by Matiasko
Matiasko replied the topic: Make "Submit" button appear only if people answer "Yes" for
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.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!