Welcome, Guest
Username: Password: Remember me

TOPIC: Default selected "Yes" for a particular question

Default selected "Yes" for a particular question 2 years 2 months ago #83487

  • amritdeep
  • amritdeep's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 34
  • Karma: 0
In my survey there is question

Que: Is it ok?
yes/no


I want that "Yes" selected by default.
for this i have used following code what didn't work


<script type="text/javascript" charset="utf-8">
document.getElementById('answer82352X12X333Y').checked = 'checked';
</script>
The administrator has disabled public write access.

Re: Default selected "Yes" for a particular question 2 years 2 months ago #83496

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1081
  • Thank you received: 240
  • Karma: 76
Try this one ;)
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
	document.getElementById('answer82352X12X333Y').checked = 'checked';
	});
</script>
Ben/
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Last Edit: 2 years 2 months ago by Ben_V.
The administrator has disabled public write access.

Re: Default selected "Yes" for a particular question 2 years 2 months ago #83509

  • amritdeep
  • amritdeep's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 34
  • Karma: 0
Its working. Thanks a lot Sir ! :) :)
The administrator has disabled public write access.

Re: Default selected "Yes" for a particular question 2 years 2 months ago #83531

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4190
  • Thank you received: 787
  • Karma: 359
You may want to put in a conditional so the default only gets checked if nothing has already been checked:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		if($('#question333 input.radio:checked').length == 0) {
			document.getElementById('answer82352X12X333Y').checked = 'checked';
		}
 
	});
</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: Default selected "Yes" for a particular question 2 years 2 months ago #83537

  • amritdeep
  • amritdeep's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 34
  • Karma: 0
This code is working for default radio buttons.

But i am using images for radio buttons.
As you described in your workaround "Use images for radio buttons and checkboxes".


In the case of "Images for radio buttons" this code is not working.


3.png


4.png
Last Edit: 2 years 2 months ago by amritdeep.
The administrator has disabled public write access.

Re: Default selected "Yes" for a particular question 1 year 11 months ago #86164

  • startx25
  • startx25's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 50
  • Karma: 0
Amritdeep, do you have find a solution, i have the same problem.

Thank for your help
The administrator has disabled public write access.

Re: Default selected "Yes" for a particular question 1 year 11 months ago #86239

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4190
  • Thank you received: 787
  • Karma: 359
In the case of "Images for radio buttons" this code is not working.
It should work with the imageTick plugin if you place the code that selects the radio button BEFORE the code that applies imageTick.
$(document).ready(function(){ 
 
	if($('#question333 input.radio:checked').length == 0) {
		document.getElementById('answer82352X12X333Y').checked = 'checked';
	}
 
	// Apply images to radios 
	$('input[type="radio"]').imageTick({ 
		// Image to use as a selected state of the radio
		tick_image_path: "upload/templates/yourTemplateName/radio.gif", 
		// Image to use as a non-selected state 
		no_tick_image_path: "upload/templates/yourTemplateName/no_radio.gif", 
		// Class to apply to all radio images that are dynamically created 
		image_tick_class: "radios"
	}); 
 
	// Apply images to checkboxes 
	$('input[type="checkbox"]').imageTick({ 
		// Image to use as a selected state of the checkbox  
		tick_image_path: "upload/templates/yourTemplateName/check.gif",  
		// Image to use as a non-selected state 
		no_tick_image_path: "upload/templates/yourTemplateName/no_check.gif", 
		// Class to apply to all checkbox images that are dynamically created 
		image_tick_class: "checkboxes" 
	}); 
});
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: Default selected "Yes" for a particular question 1 year 11 months ago #86274

  • startx25
  • startx25's Avatar
  • OFFLINE
  • Senior Lime
  • Posts: 50
  • Karma: 0
Thank you very much tpartner

That's work fine : BEFORE the code that applies imageTick.

Regards,
Startx25
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.140 seconds
Donation Image