Welcome, Guest
Username: Password: Remember me

TOPIC: Dropdown in Multiple short text

Dropdown in Multiple short text 2 years 9 months ago #69926

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Is it possible with javascript to change one of the short text fields in a Multiple short text into a standard dropdown list?

I managed with a lot of help to make a preselect dropdown, so I guess it is possible to make a standard dropdown also?
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Re: Dropdown in Multiple short text 2 years 9 months ago #69935

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4132
  • Thank you received: 763
  • Karma: 347
Have a look at the Autocomplete workaround - docs.limesurvey.org/Workarounds%3A+Manip...y#and_later_versions
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.

Re: Dropdown in Multiple short text 2 years 9 months ago #69948

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Thats an autocomplete, which I use elsewhere. What I am looking for now is a normal dropdown box.

If you for example accidentally make the wrong choice in the autocomplete above, the list will not open again until you remove the text which is there.
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Re: Dropdown in Multiple short text 2 years 9 months ago #69964

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4132
  • Thank you received: 763
  • Karma: 347
Okay, to do that you will need to use JavaScript to:
- Define the select element (dropdown)
- Hide the text input
- Insert the select elements
- Initially select an option if the question has already been answered
- Insert selected values into the hidden text input when the dropdown is changed

Add the following script to the source of the your question.

Replace "QQ" with the question ID and "NN" with the row number of the text input you would like to replace.

Modify the HTML for the dropdown as required.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		var qID = QQ;
		var inputNum = NN;
 
		// Define the select element (dropdown)
		var select1 = '<select id="select1"> \
							<option value="">-- Please Choose --</option> \
							<option value="Apples">Apples</option> \
							<option value="Oranges">Oranges</option> \
							<option value="Pears">Pears</option> \
							<option value="Bananas">Bananas</option> \
						</select>';
 
		// Hide the text input
		$('#question'+qID+' li:eq('+(inputNum-1)+') input.text').hide().parent().hide();
 
		// Insert the select elements
		$('#question'+qID+' li:eq('+(inputNum-1)+')').append(select1);
 
		// Initially select an option if the question has already been answered
		if($('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val()) {
			$('#question'+qID+' li:eq('+(inputNum-1)+') select').val($('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val())
		}
 
		// Listener on the dropdowns - insert selected values into hidden text input
		$('#question'+qID+' select').change(function() {
			$(this).siblings('span').children('input.text').val($(this).val());
		});
 
		// Some styles
		$('#question'+qID+' select').css({
			'margin':'0.3em 0 0 1em'
		});
	});
 
</script>
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.

Re: Dropdown in Multiple short text 2 years 9 months ago #69982

  • waitz
  • waitz's Avatar
  • OFFLINE
  • Gold Lime
  • Posts: 171
  • Thank you received: 1
  • Karma: 3
Yepp, fantastic! Thanks
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
The administrator has disabled public write access.

Re: Dropdown in Multiple short text 2 years 8 months ago #70010

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 248
waitz wrote:
Yepp, fantastic! Thanks
buddybeers.com/en :cheer:

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Dropdown in Multiple short text 1 year 10 months ago #86717

  • bogdant
  • bogdant's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 1
  • Karma: 0
Would it be possible to replace more text elements with dropdowns ?
The administrator has disabled public write access.

Re: Dropdown in Multiple short text 1 year 10 months ago #86719

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4132
  • Thank you received: 763
  • Karma: 347
Yes, simply repeat the script with different question IDs or row numbers.
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.

Re: Dropdown in Multiple short text 1 year 10 months ago #86752

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6272
  • Thank you received: 800
  • Karma: 240
tpartner wrote:
Replace "QQ" with the question ID and "NN" with the row number of the text input you would like to replace.
Since 1.91 (or before) you can use :
var qid={QID}

;)
Denis
The administrator has disabled public write access.

Re: Dropdown in Multiple short text 1 year 7 months ago #90859

  • Gabriela
  • Gabriela's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 64
  • Karma: 0
is it possible to do the same with an answerID? (#answer1234566)
in a matrix text?
thanks
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.167 seconds
Donation Image