Check out the LimeSurvey source code on GitHub!

Issues with 'mandatory' list box question - solutions?

5 years 6 months ago - 5 years 6 months ago #64255 by doodsonj_duplicate
Hi Team,

I have a situation that I would like to resolve and have two solutions, but I'm not sure if it is possible. You could probably ignore the scenario section, and move straight to the solutions (the scenario section just highlights why I want to do the following and might help suggest another solution).

I have a drop-down list box, associated with some javascript code that runs when the 'Next' button is clicked. The code isn't hugely relevant but the code checks the contents of some cells based on the contents of other cells.

When the drop-down list box is an optional answer, the 'No answer' option does appear. When the drop-down list box is mandatory, the 'No answer' option does not appear. However, I want to get rid of the default 'No answer' option somehow, and instead include my own 'No answer' option which would be just like any other answer in that question. The reasoning behind this is related to the 'Answer codes' that each option in a list box is assigned in LimeSurvey.

Specifically, the default 'No answer' option has a blank answer code which is the same answer code as the 'Please select...'. It is therefore difficult to determine whether the user clicked 'No answer' (indicating an active choice to not answer the question) or 'Please select...' (perhaps suggesting that the choice to miss the question might have been a mistake). By having my own 'No answer' with a unique answer code, I can make this distinction.

As an aside... I have to get Answer codes (" ", "1", "2"," ") rather than the actual plaintext (i.e. "Please choose..."; "Option1","Option2","No answer") that was selected. This is for two reasons: 1) to trying to make the code applicable for all response languages, and 2) I want the final data output to indicate which option was chosen.

I have two solutions that I can suggest but don't know if they're possible.

When a user clicks Next/submit button, is it possible to bypass the 'mandatory question' check (i.e. when each mandatory question is checked for input)? This would be via script and would not be solved by simply changing the 'mandatory' status of the question to 'No'.

If you've read the scenario then this will make sense: This would allow me to turn the question into a mandatory question, thus removing the default 'No answer' option, and allowing the only 'No answer' option to me the item that I included.

Is it possible to dynamically remove an item from the listbox (i.e. the default 'No answer' item).

If you've read the scenario then this will make sense: The remove item would not be able to refer to the Answer code (because the answer code for the default "No answer' is blank). Instead, one would have to refer to the order in which items are displayed in the list.

Any other ideas? Or other suggestions. No worries if not as I know there has been a lot to read :)

This would be achieved by java/jscript I presume.

I hope I haven't bored you.

Last Edit: 5 years 6 months ago by doodsonj_duplicate. Reason: clarification

Please Log in to join the conversation.

5 years 6 months ago #64261 by tpartner
The following script should remove the last list item if it has a value == "".
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
			if($('option:last', this).attr('value') == '') { 
				$('option:last', this).remove();

But, but, why not use the Show "No answer" setting in Survey properties --> General settings --> Presentation & navigation?

Tony Partner

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

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form