Hello: how would you do a conditional statement based on the language selected? I can get it to recognize the default language, but it doesn't apply to the language changed to. For example, if my default language was English, the proper output displays. If I change to Spanish using the following, it does not change. var language = "This is English";if(jQuery("select#Q_lang").val() == 'ES-ES') { var language = "This is Spanish";} jQuery('#demo').html(language);
Thanks TomG.
Thanks TomG. I fixed 1 + 2. How/where do you include date format? I tried adding to the variable, but misunderstand where it's supposed to be applied. For example here's the updated code:var input = jQuery("#"+this.questionId+" .InputText"); input.focusout(function(){ var age = moment().diff(moment(input.val()), 'years');console.log(age); });I've tried the following:moment().format('MM-DD-YYYY');andvar age = moment().format('MM-DD-YYYY').diff(moment(input.val()), 'years');andvar age = moment().diff(moment(input.val()), 'years').format('MM-DD-YYYY');All still produce that error.
Qualtrics.SurveyEngine.addOnReady(function(){ /*Place your JavaScript here to run when the page is fully displayed*/// This is not calculating the age. It returns 0 jQuery("#"+this.questionId+" .InputText.QR-QID1").focusout(function(){ var age = moment().diff(moment(jQuery("#"+this.questionId+" .InputText.QR-QID1").val()), 'years');Qualtrics.SurveyEngine.setEmbeddedData('age', age); console.log(age); // This is writing the DOB to console var dob = jQuery(".InputText.QR-QID1").val(); console.log(dob); // This is actually calculating the age, but posting a depraction warning: moment.js:293 Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info. var newage = moment().diff(moment(jQuery(".InputT
Even if I place inside like this under .addOnReady, the console is printing 0:jQuery("#"+this.questionId+" .InputText.QR-QID1").focusout(function(){var age = moment().diff(moment(jQuery("#"+this.questionId+" .InputText.QR-QID1").val()), 'years');Qualtrics.SurveyEngine.setEmbeddedData('age', age); console.log(age); Thoughts?
Can moment.js work on addOnReady? I tried the following setup to set an embedded value of an age calculation when you off focus, however, it's not working. I only am able to get it to work on page submit in your example above:var age = moment().diff(moment(jQuery("#"+this.questionId+" .InputText").val()), 'years');jQuery("#"+this.questionId+" .InputText.QR-QID1").focusout(function(){Qualtrics.SurveyEngine.setEmbeddedData('age', age); console.log(age); });Any thoughts on calculating before the page submits?
I figured it out. I needed to target the full class .inputText.QR-QID2-3t. There's a small bug though -- when I add JS, it sets the fields width style from 50% to 60px. Any thoughts?
@Akdashboard, I received the same error even after placing the JS in the instructed location. @TomG, I attempted to use cleave.js and loaded into the head of my survey, but not succeeding at targeting the specific phone field. I'd like to use the .input-10 example here: https://jsfiddle.net/nosir/aLnhdf3z/ However, I've tried .InputText and looked in my browser inspector to use another class (.QR-QID2-3), but I'm unsuccessful in targeting. Is there a way of adding a unique class to a field? Also, in the fields JS, I added: Qualtrics.SurveyEngine.addOnload(function() { /*Place your JavaScript here to run when the page loads*/ }); Qualtrics.SurveyEngine.addOnReady(function() { /*Place your JavaScript here to run when the page is fully displayed*/ new Cleave('.QR-QID2-3t', { numericOnly: true, blocks: [0, 3, 0, 3, 4], delimiters: ["(", ")", " ", "-"] }); }); Qualtrics.SurveyEngine.addOnUnload(function() { /*Place your JavaScript here to run when the page is unloa
Already have an account? Login
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
Sorry, our virus scanner detected that this file isn't safe to download.