hello I will appreciate your support
I have a text box where a number is entered, and it should calculate a sample size, which should be saved in an embedded data and displayed at the end of four of the same question.
My problem is that my code is activated only if after adding the number I must click on another question and then the script question.
code:
Qualtrics.SurveyEngine.addOnload(function()
{
var tamuestra;
var inputs = $(this.getQuestionContainer()).select('input[type="text"]');
var input = inputs[0];
$(input).insert({before: ' '});
$(input).insert({after: ' '});
this.questionclick = function(event,element)
{
console.log(event, element);
var choiceNum = this.getChoiceValue(1);
if (choiceNum != '')
{
tamuestra = Math.round((0.9604*choiceNum)/((0.0025*(choiceNum-1))+0.9604));
if (choiceNum < 50)
{
tamuestra = choiceNum;
}
$(input).insert({after: 'Tamaño de muesta: '+tamuestra});
Qualtrics.SurveyEngine.setEmbeddedData("ExternalDataReference", tamuestra);//lo guarda en dato embebido
}
}
});
----------
Tengo un cuadro de texto donde se introduce un número, y debe calcular un tamaño de muestra, que debe guardarse en un dato embebido y mostrarse al final del cuatro de la misma pregunta.
Mi problema es que mi codigo se activa solo si después de agregar el numero debo dar clic en otra pregunta y luego a la pregunta del script.
Solved
Result of a text box calculation DataE (Resultado de un calculo delante del textbox & Dato Embebido)
Best answer by TomG
1. "click" isn't the appropriate event. You should be using "blur" or "input"
Ray- Where can I find documentation and examples to apply this type of event?
Since you are using prototypejs see: http://api.prototypejs.org/dom/Event/on/
2. "this" inside the event handler refers to the event, not the question object. So, this.getChoiceValue() is invalid.
Ray- I deleted the "this" but the script does not run
Save the value of 'this' as another variable before the event handler (e.g., var qobj = this), then use it within the event handler (e.g., qobj.getChoiceValue())
4. inserting 'Tamaño de muesta: ' inside the event handler will add a new occurrence each time the event handler is fired.
Ray- Will you have a page where I can see examples?
Create an empty element before the event handler and update its contents with .innerHTML inside the event handler.
5. You should use a different embedded data name. ExternalReferenceData is specifically for populating an external data reference from a contact list.
Ray- It's a public survey and I don't have embedded data, but can I use the RecipientFirstName, which is a field I don't use, or is there a way to create a custom embedded data for public surveys?
You can name an embedded data variable anything you want (e.g., sampSize). You should avoid using built-in embedded variable names that have a special purpose like ExternalReferenceData and RecipientFirstName.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
