Welcome, Guest
Username: Password: Remember me

TOPIC: Changing code in qanda.php

Changing code in qanda.php 3 years 3 months ago #64366

Dear Limers,
I Have a question regarding a design issue. I want to show a question like in my updated picute and want not to show buttons for answering but instead of the buttons numbers like 1 2 3 4.

What do I have to change in my qanda.php?
I must give the labels the values of their input. I know. But how?
My programming is not that good. So I would by glad for some help.
Thank you soooooo much!
Attachments:
The administrator has disabled public write access.

Re: Changing code in qanda.php 3 years 3 months ago #64372

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4367
  • Thank you received: 828
  • Karma: 381
I would not mess around with quanda.php. That will leave you exposed to over-writing when updating.

I would do it with JavaScript. (this example is for the "Array" question type)

1) Set up your survey to use JavaScript.

2) Add the following script to the source of the array. Replace "QQ" with the array question ID.

The script replaces the radio buttons with their values. When an answer cell is clicked, it is given a class "selectedRadio" so you can style it.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		// Call the function with the question ID
		labelReplace(QQ);
 
		// A function to replace radio inputs with their values
		function labelReplace(qID) {
 
			// Hide the radio buttons and insert the labels
			$('#question'+qID+' label[for^="answer"]').each(function(i){
				var val = $('input.radio', this).val();
				$(this).append(val);
				$('input.radio', this).hide();
			});
 
			// Add a class to the clicked radio cell
			$('#question'+qID+' table.question tbody td').click(function(){
				var row = $(this).parent();
				$('td', row).removeClass('selectedRadio');
				$(this).addClass('selectedRadio');
			});
		}
 
	});
 
</script>

3) Then add something like this to the end of template.css:
.selectedRadio {
	background-color: pink;
	font-weight: bold;
}
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: Changing code in qanda.php 3 years 3 months ago #64400

Hi Tony!

Thank you but there are some problems in realisation of your instruction.

1)I set up my JavaScript (I did it very often in the past so it works correctly.

For a try i build an array question with one subquestion and 4 answer options (look picture attached)


2) I added your script to the source of the question and replaced the "QQ" with the SGQA of the question. But nothimg happened.


I wondered if it could by due to the "$" in the code. I remember that I had those problems in the past. Might it be or do I have to add the script not to the source of the question but to the answer or the subquestion? I am very confused.....

I attached the question as well. Maybe I am tooooooo stupid??? :(


Thank you!
Attachments:
The administrator has disabled public write access.

Re: Changing code in qanda.php 3 years 3 months ago #64428

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4367
  • Thank you received: 828
  • Karma: 381
...and replaced the "QQ" with the SGQA of the question...
Not the SGQA, just the question ID:

Capture_2011-08-09.JPG
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: Changing code in qanda.php 3 years 3 months ago #64464

THANKSSSS! It works finde but I do not want to have the label code (which is limited due to 5 charackters but instead I want to replace wirh the answer options. (Because I want to write " not at all"...) Is there any possibility?
The administrator has disabled public write access.

Re: Changing code in qanda.php 3 years 3 months ago #64489

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4367
  • Thank you received: 828
  • Karma: 381
Change this line:
var val = $('input.radio', this).val();

To:
var val = $('input.radio', this).attr('title');
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.
The following user(s) said Thank You: UKEpsychosomatik

Re: Changing code in qanda.php 3 years 3 months ago #64616

Super, thank you sooooo much!
It works fine!

B) B) B)
The administrator has disabled public write access.

Re: Changing code in qanda.php 3 years 3 months ago #64751

Another short question and then I promise to donate:=)
Is there a possibility to make the anwer option (the text) bigger?

thank yoooooouuuuuu!
The administrator has disabled public write access.

Re: Changing code in qanda.php 3 years 3 months ago #64757

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4367
  • Thank you received: 828
  • Karma: 381
Add the following to the end of template.css. Replace "QQ" with the question ID.
#questionQQ table.question tbody td {
	font-size: 150%;
}
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.
Last Edit: 3 years 3 months ago by tpartner.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.179 seconds
Donation Image