Run user-defined functions on page load | XM Community
Skip to main content
I've built some custom functions to calculate and display values based on embedded field values. Right now the functions run whenever we click on a radio button in the survey. The code is as follows Qualtrics.SurveyEngine.addOnload(function(){ function compute_total(){ //some computations with embedded data field happen here } function drawChart(){ //some chart elements are updated here } jQuery("input[type=radio]").click(compute_total); jQuery("input[type=radio]").click(drawChart); } And this works just fine. However, I also want both these functions to run just once when the page loads. And I'm not sure how to do that. window.onload doesn't work in Qualtrics. I tried the following: Qualtrics.SurveyEngine.addOnload(function(){ function compute_total(){ //some computations with embedded data field happen here } function drawChart(){ //some chart elements are updated here } jQuery("input[type=radio]").click(compute_total); jQuery("input[type=radio]").click(drawChart); compute_total(); drawChart(); } But that doesn't work either. Any idea how to get this done? Thanks!
Nvm. I think I figured it out. There was a problem in the compute_total function that was preventing it from working properly until a radio button was clicked. Also, the following two queries worked for me: jQuery("document").ready(compute_total); jQuery("document").ready(drawChart);