Radio button and textbox combined in one question

More
4 years 1 month ago #95388 by fenden
fenden created the topic: Radio button and textbox combined in one question
Dear LimeSurvey Team,

I'm trying to create a question (default template) in which the user can either type in text into a (free standing) text box or enable a radiobutton. The both input types shall appear one below the other and must be exclusive, so that if there is text in the box, the radiobutton gets deactivated.
Unfortunately I could not accomplish this so far and would be very grateful for any help.

Greetings from Germany,
Fenden

Please Log in to join the conversation.

More
4 years 1 month ago #95392 by tpartner
tpartner replied the topic: Radio button and textbox combined in one question
Can't you just use a radio question with "Other" enabled?



Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:

Please Log in to join the conversation.

More
4 years 1 month ago #95394 by fenden
fenden replied the topic: Radio button and textbox combined in one question
The textbox has to be above the radio button and should have no text in front.

Please Log in to join the conversation.

More
4 years 1 month ago #95398 by fenden
fenden replied the topic: Radio button and textbox combined in one question
Is it possible to switch the other option with an option above? And to not give the other option a name/label?

Please Log in to join the conversation.

More
4 years 1 month ago #95399 by holch
holch replied the topic: Radio button and textbox combined in one question
You can freely choose the text that is given to the other option. You might have to put at least a space, because otherwise it probably will use the default option.

I don't think that you can move the "other" option up in LS. But probably you can do something with Javascript. But I have no clue about that.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
4 years 1 month ago #95414 by tpartner
tpartner replied the topic: Radio button and textbox combined in one question
1) Set up your survey to use JavaScript .

2) Add the following script to the source of the question. The script will hide The "Other" radio and label and move the text input to the top of the list.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// Identify this question
		var q1ID = '{QID}';
		var q1 = $('#question'+q1ID+'');
 
		// Hide the "Other" radio button and label
		$('.other-item input.radio, .other-item .answertext', q1).hide();
 
		// Move the "Other" row to the top
		$('.radio-list', q1).prepend($('.other-item', q1));
	});
</script>

Cheers,
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.

More
1 year 9 months ago #125710 by mafo
mafo replied the topic: Radio button and textbox combined in one question
Is it also possible to move the text input to a specific position, say at position 3?
I think in this case the "prepend" in the following lines has to be changed.
// Move the "Other" row to the top
		$('.radio-list', q1).prepend($('.other-item', q1));
	});
Unfortunately, I don't know how it has to be changed. Can someone help?

Please Log in to join the conversation.

More
1 year 9 months ago #125715 by tpartner
tpartner replied the topic: Radio button and textbox combined in one question
Try this:

		// Insert the "Other" row after the second row
		$('li.answer-item:eq(1)', q1).after($('.other-item', q1));

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: mafo

Please Log in to join the conversation.

More
1 year 9 months ago #125801 by mafo
mafo replied the topic: Radio button and textbox combined in one question
Thank you, that's what I need :).
Another question: Is it also possible to change the code of the "other" option such that, if it is chosen, there will be an 8 in my SPSS dataset?

Please Log in to join the conversation.

More
1 year 9 months ago #125806 by tpartner
tpartner replied the topic: Radio button and textbox combined in one question
No, not without hacking the core code. It's dead easy to recode it in SPSS though.

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: mafo

Please Log in to join the conversation.

More
1 year 9 months ago #125808 by mafo
mafo replied the topic: Radio button and textbox combined in one question
Yes, it is really easy to recode. I was just curious whether it is feasible to do this step already in LimeSurvey.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now