Current QCODE with EM

More
5 years 7 months ago #77641 by getter
getter created the topic: Current QCODE with EM
I need in a custom Javascipt which is defined in the questiontext the current questioncode.

Something like {this.qcode} would be very nice. Is there any way to get the string of the current question_id?

Please Log in to join the conversation.

More
5 years 7 months ago #77654 by DenisChenu
DenisChenu replied the topic: Current QCODE with EM
Maybe you can try with {SGQ}

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.

More
5 years 7 months ago - 5 years 7 months ago #77661 by getter
getter replied the topic: Current QCODE with EM
This i a good idea (and i didn't know this), but it is working only outside the schript-tag.

Here it is working:
<input type="text" value="{SGQ}" />

Here not:
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
var input = document.getElementById("answer{SQG}");
input.Text = 'Some cool Text!';
});
</script>
Last Edit: 5 years 7 months ago by getter.

Please Log in to join the conversation.

More
5 years 7 months ago - 5 years 7 months ago #77737 by getter
getter replied the topic: Current QCODE with EM
Update.....

Now, i don't know why it is working and also not. This is the Script:

Where do you live?

<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
//this is working now
var input = document.getElementById("answer{SGQ}");

//and this not! coord is the questioncode from the following question
var koord = document.getElementById("answer{coord.SGQA}");


MyMap(48.206085, 16.379242, input, koord);
input.placeholder = "please insert something";
koord.disabled="disabled";
});
</script>
Last Edit: 5 years 7 months ago by getter.

Please Log in to join the conversation.

More
5 years 7 months ago #77808 by TMSWhite
TMSWhite replied the topic: Current QCODE with EM
getter-

Please clarify what you are trying to do. From the script, you need to pass a value to MyMap(), which could can be done with EM like this (assuming input and coord are your variable names):
<script type="text/javascript" charset="utf-8"> 
MyMap(48.206085, 16.379242, {input}, {coord});
</script>

I'm less clear what you are trying to do with input.placeholder and koord.disabled. In both cases, you seem to want access to the actual DOM node. But, do your really need it?

Please Log in to join the conversation.

More
5 years 7 months ago - 5 years 7 months ago #77815 by getter
getter replied the topic: Current QCODE with EM
Hi,

i need inside the MyMap function access to the input fields, because of manipulation it. For this i need the id of the rendered controls. (I don't need the value). With the .placeholder the google API is writing the string as user help in the input Field. With .disabled i tried to create a field in which user input is not allowed. It is working but althoug it is in the post variables it will not be saved on the server, but this is a second problem.
Last Edit: 5 years 7 months ago by getter.

Please Log in to join the conversation.

More
5 years 7 months ago #77816 by TMSWhite
TMSWhite replied the topic: Current QCODE with EM
Try using the following:
<script type="text/javascript" charset="utf-8"> 
$(document).ready(function () { 
var input = document.getElementById("{input.jsName}"); 
var koord = document.getElementById("{coord.jsName}"); 
 
MyMap(48.206085, 16.379242, input, koord); 
input.placeholder = "please insert something";
koord.disabled="disabled";
});
</script>

You can see an example of accessing EM dot notation attributes in this demo .

.jsName provides access to the hidden input element that gets POSTed, so it may solve your second problem. If you just need the SGQA part (without the 'java' or 'answer' prefix), you can use {input.sgqa} and {coord.sgqa}

Please Log in to join the conversation.

More
5 years 7 months ago #77913 by getter
getter replied the topic: Aw: Re: Current QCODE with EM
No, sorry. it isn't working.

with this:
var input = document.getElementById("{input.jsName}");

i get this as result:
var input = document.getElementById("<span id='LEMtailor_Q_521_35'>java24235X25X521</span>");


but i need:
var input = document.getElementById("answer24235X25X521");

Please Log in to join the conversation.

More
5 years 7 months ago #77959 by TMSWhite
TMSWhite replied the topic: Aw: Re: Current QCODE with EM
To get "answer24235X25X521", you could use "answer{input.SGQA}".

However, as you are seeing, EM-based substitutions are always dynamic (e.g. use the <span> element) when on the same page, so at present, that wouldn't work for your either. However, it should be possible to do this:
var input = document.getElementById(strip_tags("answer{input.SGQA}"));

Your question raises the broader question of whether some EM substitutions should be static, even when on the same page. The answer is probably "yes", but the development team needs to discuss this a bit.

Please Log in to join the conversation.

More
5 years 7 months ago #78041 by TMSWhite
TMSWhite replied the topic: Aw: Re: Current QCODE with EM
getter-

We've updated 1.92 so that static substitutions, like {input.SGQA} will not generate <span> tags, so this will work in the next 1.92+ release
var input = document.getElementById("answer{input.SGQA}");
The following user(s) said Thank You: getter

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!