Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Dropdown in Multiple short text

Re: Dropdown in Multiple short text 1 Jahr 6 Monate her #90886

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 748
  • Karma: 341
Sure, you can use this with IDs of array text inputs as selectors.

To use an example similar to your other post about time inputs, this code will insert the dropdowns in the first column of the array:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Text inputs to be replaced by dropdowns
		var dropdownAnswers = $('#answer97841X5X16SQ001_SQ001, #answer97841X5X16SQ002_SQ001, #answer97841X5X16SQ003_SQ001');
 
		// Define the select element (dropdown)
		var select1 = '<select class="select1 insertedSelect"> \
							<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 inputs
		$(dropdownAnswers).hide();
 
		// Insert the select elements
		$(dropdownAnswers).parents('td').append(select1);
 
		// Initially select an option if the question has already been answered
		$('.insertedSelect').each(function(i) {
			if($(this).parent().find('input[type="text"]').val()) {
				$(this).val($(this).parent().find('input[type="text"]').val())
			}
		});
 
		// Listener on the dropdowns - insert selected values into hidden text inputs
		$('.insertedSelect').change(function() {
			$(this).parent().find('input[type="text"]').val($(this).val());
		});
	});
</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.
Letzte Änderung: 1 Jahr 6 Monate her von tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 1 Jahr 6 Monate her #90892

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 748
  • Karma: 341
Oops, found a bug, use this instead:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Text inputs to be replaced by dropdowns
		var dropdownAnswers = $('#answer97841X5X16SQ001_SQ001, #answer97841X5X16SQ002_SQ001, #answer97841X5X16SQ003_SQ001');
 
		// Define the select element (dropdown)
		var select1 = '<select class="select1 insertedSelect"> \
							<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 inputs
		$(dropdownAnswers).hide();
 
		// Insert the select elements
		$(dropdownAnswers).closest('td').append(select1);
 
		// Initially select an option if the question has already been answered
		$('.insertedSelect').each(function(i) {
			if($(this).parent().find('input[type="text"]').val()) {
				$(this).val($(this).parent().find('input[type="text"]').val())
			}
		});
 
		// Listener on the dropdowns - insert selected values into hidden text inputs
		$('.insertedSelect').change(function() {
			$(this).parent().find('input[type="text"]').val($(this).val());
		});
	});
</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 1 Jahr 6 Monate her #90919

  • Gabriela
  • Gabrielas Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 64
  • Karma: 0
Great.! works. learning too..
merci
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 1 Jahr 3 Monate her #95277

  • ricardo
  • ricardos Avatar
  • OFFLINE
  • Expert Lime
  • Beiträge: 110
  • Dank erhalten: 1
  • Karma: 0
Hi,
I created a multiple short text question and want the first row to display as a dropdown. I'm sure this is what I need. I copied this script and modified it using my QID

<script type="text/javascript" charset="utf-8">

$(document).ready(function() {

var qID = 9334;
var inputNum = 1;

// Define the select element (dropdown)
var select1 = '<select id="select1"> \
<option value="">-- Please Choose --</option> \
<option value="Mrs.">Mrs.</option> \
<option value="Mr.">Mr.</option> \
<option value="Doctor">Doctor</option> \
<option value="Miss">Miss</option> \
<option value="Other">Other</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>

However the first row is still empty...no dropdown anywhere. I'm using LS Version 2.00+ Build 130423
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 1 Jahr 3 Monate her #95279

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 748
  • Karma: 341
You have an extra line in the dropdown definition that may be causing an error. Try this:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		var qID = 9334;
		var inputNum = 1;
 
		// Define the select element (dropdown)
		var select1 = '<select id="select1"> \
							<option value="">-- Please Choose --</option> \
							<option value="Mrs.">Mrs.</option> \
							<option value="Mr.">Mr.</option> \
							<option value="Doctor">Doctor</option> \
							<option value="Miss">Miss</option> \
							<option value="Other">Other</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 1 Jahr 3 Monate her #95283

  • ricardo
  • ricardos Avatar
  • OFFLINE
  • Expert Lime
  • Beiträge: 110
  • Dank erhalten: 1
  • Karma: 0
Thanks, it worked...are you talking about this line?


thisline.PNG


I thought java scripts were immune to that?

cheers,

ricardo
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 1 Jahr 3 Monate her #95297

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 748
  • Karma: 341
...are you talking about this line?
Yes.

I thought java scripts were immune to that?
Not when you have a variable (string) which spans several lines. In that case, every line must end with a backslash character '\'. You could put the whole string on one line but it would be kinda hard to read.
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.
Letzte Änderung: 1 Jahr 3 Monate her von tpartner.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 1 Jahr 3 Monate her #95300

  • ricardo
  • ricardos Avatar
  • OFFLINE
  • Expert Lime
  • Beiträge: 110
  • Dank erhalten: 1
  • Karma: 0
Thanks, Tony.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Dropdown in Multiple short text 1 Jahr 3 Monate her #95322

  • Limer2001
  • Limer2001s Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 18
  • Dank erhalten: 2
  • Karma: 0
Can you (Ricardo,Tony?) post a limesurvey question file or survey file of this working. I can't get it to work.
Letzte Änderung: 1 Jahr 3 Monate her von Limer2001.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdown in Multiple short text 1 Jahr 3 Monate her #95324

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 4071
  • Dank erhalten: 748
  • Karma: 341
Here you go. For portability, in this test survey I replaced the question ID (9334) with the {QID} placeholder.

Dateianhang:

Dateiname: limesurvey_survey_179411.lss
Dateigröße: 16 KB
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.
Moderatoren: ITEd
Ladezeit der Seite: 0.177 Sekunden
Donation Image