Welcome, Guest
Username: Password: Remember me

TOPIC: using javascript-listener on text field arry?

using javascript-listener on text field arry? 2 years 4 months ago #69822

  • josch
  • josch's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Hey.
I want to use the workaraound that Tony suggested for listening on an arry and fill a hidden multiple choise question
(this is descriped here and here)
can anyone help me with the javascript that listens tho an array for any inserted text?
The one code that listens to radio buttons, seems to be this:
if ($('#question'+qMultiID+' input.checkbox:eq(0)').attr('checked') == true) {
$('#question'+qHiddenID+' input.radio:eq(0)').attr('checked', true);

I also liked this one, that listens to the rows and checks the correspondending ones:
$('#question'+q1ID+' td.answer_cell_002, #question'+q1ID+' td.answer_cell_003').click(function () {
// Check the corresponding option in the hidden question
var rowID = $(this).parents('tbody:eq(0)').attr('id');
var tmp2 = rowID.split('X'+q1ID); var answerCode = tmp2[1];$('#answer'+sID+'X'+gID+'X'+qHiddenID+answerCode).attr('checked', true);
I don't know much abaout javascript - is there a function to listen to the textfields in arrays? then it should be possible tho use one of the above tho check the hidden table in case "something" is written in the text fields ...

Thanks!
Josch
Last Edit: 2 years 4 months ago by josch. Reason: layout edit
The administrator has disabled public write access.

Re: using javascript-listener on text field arry? 2 years 4 months ago #69829

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
This script will put a listener on the text inputs of an array. Replace "QQ" with the array ID.
<script type="text/javascript" charset="utf-8">
 
		$(document).ready(function(){
 
		$('#questionQQ input[type="text"]').change(function(){
			alert ('Something changed!');
		});
 
	});
 
</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: using javascript-listener on text field arry? 2 years 4 months ago #69836

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 5845
  • Thank you received: 715
  • Karma: 222
And to put a listener only when input.text is complete : use api.jquery.com/blur/ :).
The administrator has disabled public write access.

Re: using javascript-listener on text field arry? 2 years 4 months ago #69910

  • josch
  • josch's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Thanks Tony,

I tried it know for some hours ... but it would'nt work.
I can put the listener on the whole array (to look if anything changed) -
but not in a single array
I thougt the array ID is the QuestionID followd by rowCode and "_" and the ColumnCode (like desciped for the SQGA).

And (2nd question) I'm also not sure, if I'm right with the idea of checking the multiple question. Can I use your code like this:

$('#question308 input[type="text"]').change(function() { $('#answerSIDXGIDXQID').attr('checked', true); });
The administrator has disabled public write access.

Re: using javascript-listener on text field arry? 2 years 4 months ago #69911

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Yes, this script listens to all text inputs ina n array.

What are you trying to do? Check a muliple-options answer if any text input in a corresponding array row is filled in?

So, for example, if a respondent enters a value in array row 3, then the multiple-options third answer is checked?
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: using javascript-listener on text field arry? 2 years 4 months ago #69912

  • josch
  • josch's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
This I understand so far.
But I would like to check not only a row or the whole array - is it possible to check for one text field in an array (text) - for example to check if something is written in the first row and second column field?
Instead of the exact field, your suggestion would work too:
Check a muliple-options answer if any text input in a corresponding array row is filled in?
So, for example, if a respondent enters a value in array row 3, then the multiple-options third answer is checked
The administrator has disabled public write access.

Re: using javascript-listener on text field arry? 2 years 4 months ago #69913

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Okay, in that case the the easiest method may be to use the indexes for each element.

Try the following script replacing "AA" with the array ID and "MM" (both of them) with the multi-options ID.

Remember that the indexes start at 0 so in the following example:
- tr:eq(0) indicates row 1 of the array
- input[type="text"]:eq(1) indicates the second input in that row
- input.checkbox:eq(2) indicates the third checkbox

<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		$('#questionAA table.question tbody tr:eq(0) input[type="text"]:eq(1)').change(function(){
 
			if($(this).val()) {
				$('#questionMM input.checkbox:eq(2)').attr('checked', true);
			}
			else {
				$('#questionMM input.checkbox:eq(2)').attr('checked', false);
			}
		});
 
 
	});
 
</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.
The following user(s) said Thank You: josch

Re: using javascript-listener on text field arry? 2 years 4 months ago #69962

  • josch
  • josch's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Thank you Tony!
This one works perfect.
The administrator has disabled public write access.

Re: using javascript-listener on text field arry? 2 years 4 months ago #70015

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5279
  • Thank you received: 289
  • Karma: 246
josch wrote:
Thank you Tony!
This one works perfect.
You're welcome!

If our hints have been helpful and you enjoy limesurvey please consider a donation to the team .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.131 seconds
Donation Image