Have you considered eliminating q4 and just adding together the values input in q5? Otherwise, custom validation may be a solve here.
@hokie404 I do need Q4 as part of the survey. I think custom validations is the only way we can do it and I don’t know too much coding. First they told me the problem was because of branching and I took all that away and still does not work. Now they say it because the question that compares them is in a different block because of the embedded data.
Wonder if
used Qualtrics validation but also used embedded data in the validation but will that allow the comparing the two totals and be in the same block? will it allow the people to go back and fix the problem(s)?
@Linda_charlton,
The questions don’t need to be in different blocks. Using JS you can calculate the total and set an embedded data field in an addOnPageSubmit function of the first question. That embedded data field can then be used on the next page (in the same block).
@TomG I think that I got it....will try again later. I decided not to use embedded data in the custom validation since the embedded data is after the question so nothing was working but your post that I link to help me figure out the problem. Thank you because I was told nothing will work for my problem.
@TomG I have a other problem but it is still tied to the same questions. I don’t know if this will work for the code or not.
Qualtrics.SurveyEngine.addOnReady(function() {
// Replace 'QR~' with the start of your question IDs
const inputs = this.questionContainer.querySelectorAll("input[id^='QR~']");
let totalMinutes = 0;
inputs.forEach(input => {
totalMinutes += parseInt(input.value) || 0;
});
const totalHours = (totalMinutes / 60).toFixed(2);
Qualtrics.SurveyEngine.setEmbeddedData("total_hours", totalHours);
});
Attached is my survey flow and the block Social Media Usage Block has the questions that have the Hours/Mins questions in it.
I used this in the custom validation for one of the questions: this is for the hours
$e{ q://QID37/ChoiceNumericEntryValue/1/1 + q://QID37/ChoiceNumericEntryValue/2/1 + q://QID37/ChoiceNumericEntryValue/3/1 + q://QID37/ChoiceNumericEntryValue/4/1 + q://QID37/ChoiceNumericEntryValue/5/1 + q://QID37/ChoiceNumericEntryValue/6/1 + q://QID37/ChoiceNumericEntryValue/7/1 + q://QID37/ChoiceNumericEntryValue/8/1 + q://QID37/ChoiceNumericEntryValue/9/1 + q://QID37/ChoiceNumericEntryValue/10/1 + q://QID37/ChoiceNumericEntryValue/11/1 + q://QID37/ChoiceNumericEntryValue/12/1 + q://QID37/ChoiceNumericEntryValue/13/1 }
When I used any embedded data nothing worked because the embedded data is on the bottom of the block and when we move the embedded data above then everything does not work because have not done the questions yet. So do I use the new embedded data for the code? if yes then how do we get it in to the validation code?
If it were me, I would add a third column for total minutes and use JS to hide it and update it each time the hours or minutes on that row changed. Then you can do validation on the total minutes column. I would do the same thing with a third field on the first question as well. Then all your comparisons/validations are in the same units - minutes.
@TomG I am sorry I don’t really know JS good enough to do anything. So would I have to start all over with the embedded data and verifications?
@TomG I am sorry I don’t really know JS good enough to do anything. So would I have to start all over with the embedded data and verifications?
Assuming you are NOT using New Experience (based on the code you posted above), you can add a third column to your constant sum matrix and use this JS to calculate total minutes for each row in that column:
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery(this.questionContainer);
//q.find("tr.Answers th:last").hide();
//q.find("td.last").hide();
q.find(".ChoiceRow td:not(.last) input").on("input", function() {
this.value = this.value.replace(/\D/g,""); //remove non-digits
var inputs = jQuery(this).closest("tr").find("input");
inputs.eq(2).val(Number(inputs.eq(0).val())*60 + Number(inputs.eq(1).val()));
if(isNaN(inputs.eq(2).val())) inputs.eq(2).val("0");
});
});
Remove the // from the 3rd and 4th line to hide the last column.
@TomG The survey is using New Experience. The code that I posted was what I found when I did a search.