Array num with radio in last column

More
3 years 8 months ago #102751 by MikeConom
MikeConom created the topic: Array num with radio in last column
Good evening

i have create an array with numbers and in the end a radio button

i am looking to find how can i do the following

1) When choosing radio button numeric fields to be 0
2) when I write in numeric fields the radio buttons to be not check

Thanks
Attachments:

Please Log in to join the conversation.

More
3 years 8 months ago - 3 years 8 months ago #102754 by tpartner
tpartner replied the topic: Array num with radio in last column
This should do the trick. Note that this code must be placed after your code that inserts the radios.

<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function(){
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Listener on the radios
		$('tr.subquestions-list input[type="radio"]', thisQuestion).click(function(event) {
			var thisRow = $(this).closest('tr.subquestions-list');
			$('input[type="text"]', thisRow).val('');
		});
 
		// Keyup listener on the text inputs
		$('tr.subquestions-list input[type="text"]', thisQuestion).keyup(function(event) {
			if($(this).val() != ''){
				var thisRow = $(this).closest('tr.subquestions-list');
				$('input[type="radio"]', thisRow).attr('checked', false);
			}
		});
 
		// Paste listener on the text inputs
		$('tr.subquestions-list input[type="text"]', thisQuestion).bind('paste', function () {
			var thisInput = $(this);		
			setTimeout(function() {	 // Little timeout so the val() is available
				if($(thisInput).val() != ''){
					var thisRow = $(thisInput).closest('tr.subquestions-list');
					$('input[type="radio"]', thisRow).attr('checked', false);
				}
			}, 100);
		});
	});
</script>

Here is the survey back with the amended code.

File Attachment:

File Name: limesurvey...5833.lss
File Size:17 KB


.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last Edit: 3 years 8 months ago by tpartner.

Please Log in to join the conversation.

More
3 years 8 months ago #102756 by tpartner
tpartner replied the topic: Array num with radio in last column
I should point out that I assumed you are using LS 2.0.

If using 2.05,the code would be slightly different:
<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function(){
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Listener on the radois
		$('tr.subquestions-list input[type="radio"]', thisQuestion).click(function(event) {
			var thisRow = $(this).closest('tr.subquestions-list');
			$('input[type="text"]', thisRow).val('');
		});
 
		// Keyup listener on the text inputs
		$('tr.subquestions-list input[type="text"]', thisQuestion).keyup(function(event) {
			if($(this).val() != ''){
				var thisRow = $(this).closest('tr.subquestions-list');
				$('input[type="radio"]', thisRow).prop('checked', false);
			}
		});
 
		// Paste listener on the text inputs
		$('tr.subquestions-list input[type="text"]', thisQuestion).bind('paste', function () {
			var thisInput = $(this);		
			setTimeout(function() {	 // Little timeout so the val() is available
				if($(thisInput).val() != ''){
					var thisRow = $(thisInput).closest('tr.subquestions-list');
					$('input[type="radio"]', thisRow).prop('checked', false);
				}
			}, 100);
		});
	});
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: MikeConom

Please Log in to join the conversation.

More
3 years 8 months ago #102763 by MikeConom
MikeConom replied the topic: Array num with radio in last column
Partner thanks for your support.
As i see the different betwwen LS 2.0 and 2.5 is the .prop and .attr
That means when i have to change version i have to take care for this different.

Thanks
Mike Conom

Please Log in to join the conversation.

More
3 years 8 months ago #102764 by tpartner
tpartner replied the topic: Array num with radio in last column
Yes, in jQuery 1.6.1 the .prop() method was introduced and replaced several uses of the .attr() method (and pissed off LOTS of developers) - blog.jquery.com/2011/05/12/jquery-1-6-1-released/

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
3 years 8 months ago #102770 by MikeConom
MikeConom replied the topic: Array num with radio in last column
Partner good morning

I have a hidden question and depence from the days.
when the days are Greater than 3 then the hidden question appear.
When i press the radio button and the days is empty, the question is still visible.
i tried with many methods like focus in days and press backspace or put number less than 3
but i cant find solution.

have you a solution for this?

Thanks
Attachments:

Please Log in to join the conversation.

More
3 years 8 months ago - 3 years 8 months ago #102779 by tpartner
tpartner replied the topic: Array num with radio in last column
In that case, you will need to fire the fixnum_checkconditions() function for all text inputs in a row when a radio is clicked.

<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function(){
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Listener on the radois
		$('tr.subquestions-list input[type="radio"]', thisQuestion).click(function(event) {
			var thisRow = $(this).closest('tr.subquestions-list');
			$('input[type="text"]', thisRow).val('');
			// Check conditions...
			$('input[type="text"]', thisRow).each(function(i) {
				fixnum_checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
			});
		});
 
		// Keyup listener on the text inputs
		$('tr.subquestions-list input[type="text"]', thisQuestion).keyup(function(event) {
			if($(this).val() != ''){
				var thisRow = $(this).closest('tr.subquestions-list');
				$('input[type="radio"]', thisRow).prop('checked', false);
			}
		});
 
		// Paste listener on the text inputs
		$('tr.subquestions-list input[type="text"]', thisQuestion).bind('paste', function () {
			var thisInput = $(this);		
			setTimeout(function() {	 // Little timeout so the val() is available
				if($(thisInput).val() != ''){
					var thisRow = $(thisInput).closest('tr.subquestions-list');
					$('input[type="radio"]', thisRow).prop('checked', false);
				}
			}, 100);
		});
	});
</script>


File Attachment:

File Name: limesurvey...4541.lss
File Size:19 KB



.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last Edit: 3 years 8 months ago by tpartner.
The following user(s) said Thank You: MikeConom

Please Log in to join the conversation.

More
3 years 8 months ago #102796 by MikeConom
MikeConom replied the topic: Array num with radio in last column
It was my first step when i was looking for the solution, but i forgot to execute each(function(i)

Have a nice evening

Thanks

Please Log in to join the conversation.

More
3 years 8 months ago #103161 by MikeConom
MikeConom replied the topic: Array num with radio in last column
Tony

My best wishes for a happy new year.

Is it possible to check the radio button for the next question?

I have try with many conditions but i cant find the solution.

Thanks
Attachments:

Please Log in to join the conversation.

More
3 years 8 months ago #103169 by tpartner
tpartner replied the topic: Array num with radio in last column
Sorry, I don't understand the question.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
3 years 8 months ago #103172 by MikeConom
MikeConom replied the topic: Array num with radio in last column
When i choose the r1 (radio button) then the next question to be visible

Please Log in to join the conversation.

More
3 years 8 months ago #103204 by tpartner
tpartner replied the topic: Array num with radio in last column
Okay, the way that I would handle that would be to supplement the listener on the radios to load their value into the hidden text inputs when clicked (I suspect you want that anyway). Then you can fire the fixnum_checkconditions() function as discussed previously.
<script type="text/javascript" charset="utf-8">$(document).ready(function() {
 
		// Identify this question
		var qID = {QID};
		var thisQuestion = $('#question'+qID);
 
		// Define the select element (radio)
		var select1 = '<div id="insertedRadio"> \
		<input type="radio" title="ans_1" value="1" name="Radio1" /> \
		</div>';
		var select2 = '<div id="insertedRadio"> \
		<input type="radio" title="ans_2" value="2" name="Radio1" /> \
		</div>';
 
		// Hide the text inputs
		$('#question'+qID+' .answer_cell_005 input[type="text"]').addClass('hidden').hide();
		$('#question'+qID+' .answer_cell_006 input[type="text"]').addClass('hidden').hide();
 
		// Insert the select elements
		$('#question'+qID+' .answer_cell_005').append(select1);
		$('#question'+qID+' .answer_cell_006').append(select2);
 
		// Listener on the radios
		$('tr.subquestions-list input[type="radio"]', thisQuestion).click(function(event) {
			var thisRow = $(this).closest('tr.subquestions-list');
			var thisCell = $(this).closest('td.question-item');
			var thisTextInput = $('input[type="text"]', thisCell);
			$('input[type="text"]', thisRow).val('');
			$('input[type="text"]', thisCell).val($(this).attr('value'));
			// Check conditions...
			checkThisRowConditions(thisRow)
		});
 
		// Keyup listener on the text inputs
		$('tr.subquestions-list input[type="text"]', thisQuestion).keyup(function(event) {
			if($(this).val() != ''){
				var thisRow = $(this).closest('tr.subquestions-list');
				$('input[type="radio"]', thisRow).attr('checked', false);
				$('input[type="text"].hidden', thisRow).val('');
				// Check conditions...
				checkThisRowConditions(thisRow)
			}
		});
 
		// Paste listener on the text inputs
		$('tr.subquestions-list input[type="text"]', thisQuestion).bind('paste', function () {
			var thisInput = $(this);		
			setTimeout(function() {	 // Little timeout so the val() is available
				if($(thisInput).val() != ''){
					var thisRow = $(thisInput).closest('tr.subquestions-list');
					$('input[type="radio"]', thisRow).attr('checked', false);
					$('input[type="text"].hidden', thisRow).val('');
					// Check conditions...
					checkThisRowConditions(thisRow)
				}
			}, 100);
		});
 
		function checkThisRowConditions(thisRow) {
			$('input[type="text"]', thisRow).each(function(i) {
				fixnum_checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
			});
		}
	});
</script>

File Attachment:

File Name: limesurvey...5454.lss
File Size:20 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: MikeConom

Please Log in to join the conversation.

More
3 years 8 months ago #103236 by MikeConom
MikeConom replied the topic: Array num with radio in last column
Ok Tony

this is the solution and its working fine

Also i have added a new line in section Listener on the radios
$('input[type="text"]', thisTextInput).val($(this).attr('value'));
so keep in results the value of radio

Thanks

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now