Hi @Anahivette
Please try the below code in your text entry question (I have added ‘$’ as the currency sign, you can replace it according to your requirement).
Qualtrics.SurveyEngine.addOnload(function() {
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function() {
// Add your input box class or ID
var inputBox = jQuery(".InputText"); // Replace with your actual class or ID
inputBox.on("cut copy paste", function (e) {
e.preventDefault();
});
inputBox.on('input', function () {
// Remove non-numeric characters except for periods (.)
var sanitizedValue = this.value.replace(/z^0-9.]/g, '');
// Limit to two decimal places
var decimalIndex = sanitizedValue.indexOf('.');
if (decimalIndex !== -1) {
sanitizedValue = sanitizedValue.substr(0, decimalIndex + 3);
}
// Format the number with commas and add $ sign
this.value = "$" + addCommas(sanitizedValue);
});
function addCommas(value) {
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function() {
/*Place your JavaScript here to run when the page is unloaded*/
});
@omkarkewat Thank you!! That worked!
I’m assuming the “addCommas” works for all currency that follows this convention in thousands but not in lakhs. Is there a code for inserting commas in the Indian lakh style?