Hi everyone,
Is it possible to get/limit the value to 100% in text entries in Side by Side Question?
See attached picture. On the last column. I want to get and limit the sum of percentages of 4 text entries to 100% on this type of question.
robi_kalinisan
You can do the total via the below JS (Refer this source)
Qualtrics.SurveyEngine.addOnload(function()
{
/Place your JavaScript here to run when the page loads/
jQuery('.SBS2 input:last').prop('disabled',true);
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/Place your JavaScript here to run when the page is fully displayed/
var $jq = jQuery.noConflict();// always keep this
$jq('input[type="text"]').after('%'); //insert % sign after boxes
$jq('.SBS1 select:last').hide(); // remove last select for Column 1
$jq('.SBS3 select:last').hide(); // remove last select for Column 3
$jq('.SBS4 select:last').hide(); // remove last select for Column 4
var $sum = 0; // define sum variable
$jq('.SBS2 input:last').val($sum); // setting the value of total box
//function for changing text value to numeric
function getVal(val){ var num = parseInt(val); if(isNaN(num)) { num = 0; } return num; };
// calculating some on change
$jq('.SBS2 input').not(':last').change(function(){
// for every box
var $sum = 0; // define sum variable
$jq('.SBS2 input').not(':last').each(function(){
$sum += +getVal($jq(this).val());
});
$jq('.SBS2 input:last').val($sum);
});
});
And add a custom validation for that text value to be 100 and show an error based on it.
If it isn't 100 you can show an error message that total isn't 100.
Hope it helps!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.