Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Dropdown in Multiple short text

Dropdown in Multiple short text 2 Jahre 10 Monate her #69926

  • waitz
  • waitzs Avatar
  • OFFLINE
  • Gold Lime
  • Beiträge: 171
  • Dank erhalten: 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 |
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 2 Jahre 10 Monate her #69935

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4271
  • Dank erhalten: 806
  • Karma: 369
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 2 Jahre 10 Monate her #69948

  • waitz
  • waitzs Avatar
  • OFFLINE
  • Gold Lime
  • Beiträge: 171
  • Dank erhalten: 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 |
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 2 Jahre 10 Monate her #69964

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4271
  • Dank erhalten: 806
  • Karma: 369
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 2 Jahre 10 Monate her #69982

  • waitz
  • waitzs Avatar
  • OFFLINE
  • Gold Lime
  • Beiträge: 171
  • Dank erhalten: 1
  • Karma: 3
Yepp, fantastic! Thanks
Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 2 Jahre 10 Monate her #70010

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5331
  • Dank erhalten: 296
  • Karma: 249
waitz schrieb:
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'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 2 Jahre 1 Woche her #86717

  • bogdant
  • bogdants Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 1
  • Karma: 0
Would it be possible to replace more text elements with dropdowns ?
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 2 Jahre 1 Woche her #86719

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4271
  • Dank erhalten: 806
  • Karma: 369
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 2 Jahre 1 Woche her #86752

  • DenisChenu
  • DenisChenus Avatar
  • ONLINE
  • Moderator Lime
  • Beiträge: 6447
  • Dank erhalten: 841
  • Karma: 249
tpartner schrieb:
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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 1 Jahr 9 Monate her #90859

  • Gabriela
  • Gabrielas Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 64
  • Karma: 0
is it possible to do the same with an answerID? (#answer1234566)
in a matrix text?
thanks
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.180 Sekunden
Donation Image