Welcome, Guest
Username: Password: Remember me

TOPIC: Issues with 'mandatory' list box question - solutions?

Issues with 'mandatory' list box question - solutions? 3 years 2 months ago #64255

  • doodsonj
  • doodsonj's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 30
  • Thank you received: 2
  • Karma: 2
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).

SCENARIO
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.

SOLUTION 1:
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.

SOLUTION 2:
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.

J.
Last Edit: 3 years 2 months ago by doodsonj. Reason: clarification
The administrator has disabled public write access.

Re: Issues with 'mandatory' list box question - solutions? 3 years 2 months ago #64261

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4270
  • Thank you received: 803
  • Karma: 368
The following script should remove the last list item if it has a value == "".
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		$('.list-dropdown').each(function(){
			if($('option:last', this).attr('value') == '') { 
				$('option:last', this).remove();
			}
		});
 
	});
 
</script>

But, but, why not use the Show "No answer" setting in Survey properties --> General settings --> Presentation & navigation?
Capture_2011-08-04.JPG
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.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.111 seconds
Donation Image