Welcome, Guest
Username: Password: Remember me

TOPIC: Current QCODE with EM

Current QCODE with EM 2 years 6 months ago #77641

  • getter
  • getter's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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?
The administrator has disabled public write access.

Re: Current QCODE with EM 2 years 6 months ago #77654

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6451
  • Thank you received: 844
  • Karma: 249
Maybe you can try with {SGQ}

Denis
The administrator has disabled public write access.

Re: Current QCODE with EM 2 years 6 months ago #77661

  • getter
  • getter's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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: 2 years 6 months ago by getter.
The administrator has disabled public write access.

Re: Current QCODE with EM 2 years 6 months ago #77737

  • getter
  • getter's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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: 2 years 6 months ago by getter.
The administrator has disabled public write access.

Re: Current QCODE with EM 2 years 6 months ago #77808

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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?
The administrator has disabled public write access.

Re: Current QCODE with EM 2 years 6 months ago #77815

  • getter
  • getter's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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: 2 years 6 months ago by getter.
The administrator has disabled public write access.

Re: Current QCODE with EM 2 years 6 months ago #77816

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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}
The administrator has disabled public write access.

Aw: Re: Current QCODE with EM 2 years 6 months ago #77913

  • getter
  • getter's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 13
  • Karma: 0
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");
The administrator has disabled public write access.

Re: Aw: Re: Current QCODE with EM 2 years 6 months ago #77959

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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.
The administrator has disabled public write access.

Re: Aw: Re: Current QCODE with EM 2 years 6 months ago #78041

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
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 administrator has disabled public write access.
The following user(s) said Thank You: getter
Moderators: ITEd
Time to create page: 0.351 seconds
Donation Image