Help! Javascript syntax for definitions

More
4 years 6 months ago - 4 years 6 months ago #93391 by rodriguezm1
rodriguezm1 created the topic: Help! Javascript syntax for definitions
I have a multi-text question, Q1. It has a subquestion, sq1. Q1 is hidden.

I want to use java to insert an answer to Q1_sq1.

What is the syntax?

I've tried
 
document.getElementById('{Q1_sq1}').value = 'new text';
$('#answer{Q1_sq1}').val() = 'new text';
$('#answer{Q1_sq1}').text() = 'new text';
$('#answer{Q1_sq1}').val('new text');
 

None of this works. I would really appreciate your help in telling me how to do something that should be so fundamentally simple, which is define a variable. I don't understand why this doesn't work in LimeSurvey easily.
Last Edit: 4 years 6 months ago by rodriguezm1.

Please Log in to join the conversation.

More
4 years 5 months ago #94551 by kubaj
kubaj replied the topic: Help! Javascript syntax for definitions
Hi,

you can try document.getElementById('answer'+id_of_question_variable).value = 'whatever';

id_of_question_variable is for example 13453X34X34_abc for field in array question

Please Log in to join the conversation.

More
4 years 5 months ago #94592 by DenisChenu
DenisChenu replied the topic: Help! Javascript syntax for definitions
Hello,

Try this:
$('#answer{Q1_sq1.SGQA}').val('new text');

And if you are on the question text:
$('#answer{SGQ}sq1').val('new text');
(if the code is sq1).


Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now