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('inputttype="text"]');
var input = inputst0];
$(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.
There are a number of issues with your code:
- "click" isn't the appropriate event. You should be using "blur" or "input"
- "this" inside the event handler refers to the event, not the question object. So, this.getChoiceValue() is invalid.
- You should convert choiceNum to a number.
- inserting 'Tamaño de muesta: ' inside the event handler will add a new occurrence each time the event handler is fired.
- You should use a different embedded data name. ExternalReferenceData is specifically for populating an external data reference from a contact list.
Thank you very much for your answer TomG, I was looking for solutions based on your answer, however I still do not find it, I hope you can continue guiding me:
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?
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
3. You should convert choiceNum to a number. Ray- Change applied thanks
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?
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?
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.
thanks, I solved it by placing the code in another question that clicking on it brings the data from the previous question and calculates
Qualtrics.SurveyEngine.addOnload(function()
{
var tamuestra=0;
var answer = Number(document.getElementById('QR~QID5').value);
this.questionclick = function(event,element)
{
//console.log(event, element);
alert('LAUUU¡¡¡ ');
answer = Number(document.getElementById('QR~QID5').value);
if (answer != '')
{
tamuestra = Math.round((0.9604*answer)/((0.0025*(answer-1))+0.9604));
if (answer < 50)
{
tamuestra = answer;
}
alert('Tamaño de muestra '+tamuestra);
Qualtrics.SurveyEngine.setEmbeddedData("RecipientFirstName", tamuestra);//lo guarda en dato embebido
}
}
});
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.