Solved
Can I use Javascript to convert Text Entry > Form question to a drop down selection?
I have a Text Entry > Form question on a survey, with about 10 component questions in it (e.g. Name, Project Title, Phone, Email, etc.). They all require text response. I want to convert two of those component questions to drop down lists, because the responses should be limited to pre-determined values.
Is it possible to use JS on the form question to target those two components and convert their response types to drop downs?
Or is there a non-coding possibility that would make this possible while still maintaining the form question type?
Or should I just remove the form question and make all the components their own questions (assigning MC > Drop down to the two in question)?
Thank you!
Best answer by Anonymous
Hello @JonathonJames ,
We can achieve this using JS - Hide the Input text of those two question and replace it with Select element, then on change event of select option set the selected option text to hidden text field.
Paste the below code in the js(OnReady) of the form question type.
var that=this.questionId;
var element="<select id='s1'><option ></option><option value='1'>option 1.1</option><option value='2'>option 1.2</option></select>";
jQuery(element).insertAfter("#"+that+" .InputText:eq(4)");
var element="<select id='s2'><option ></option><option value='1'>option 2.1</option><option value='2'>option 2.2</option></select>";
jQuery(element).insertAfter("#"+that+" .InputText:eq(5)");
jQuery("#"+that+" .InputText:eq(4)").hide();
jQuery("#"+that+" .InputText:eq(5)").hide();
jQuery("#"+that+" .InputText:eq(4)").val(jQuery("#s1 option:selected").text());
jQuery("#"+that+" .InputText:eq(5)").val(jQuery("#s2 option:selected").text());
jQuery("#s1").on('change',function(){
jQuery("#"+that+" .InputText:eq(4)").val(jQuery("#s1 option:selected").text());
});
jQuery("#s2").on('change',function(){
jQuery("#"+that+" .InputText:eq(5)").val(jQuery("#s2 option:selected").text());
});
So the above code will hide the 5th and 6th form filed input text and replace it with drop-down.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
