I am having trouble coding questions to automatically format numbers. I am dealing with revenues and in the hundreds of thousands and millions. I do have the telepad coded for the question already. I am new to javascript and coding in general.
What code would work to make it delimit three digits per comma to separate by the thousands?
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
jQuery("#"+this.questionId+" input[type='text']").attr('type', 'tel');
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*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*/
});
https://community.qualtrics.com/XMcommunity/discussion/23216/help-with-number-formattingThis link should help you achieve the desired result.
Hope it helps!
Deepak I utilized this code below:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
jQuery("#"+this.questionId+" input[type='text']").attr('type', 'tel');
var inputs = jQuery("input[type='text']");
inputs .toArray() .forEach(function(field)
{
new Cleave(field,
{
numeral: true,
numeralThousandsGroupStyle: 'thousand'
});
});
});
I would like to add '$' in the text entry box as a prefix. Do you by chance know how I would add that into the code above?
https://community.qualtrics.com/XMcommunity/discussion/comment/52802#Comment_52802If you just want it at as a default text just include it in the default choice and it would appear within the text box.
Hope it help!
Use the 'prefix' option in cleave to add a $ sign.
https://github.com/nosir/cleave.js/blob/master/doc/options.md
https://community.qualtrics.com/XMcommunity/discussion/comment/52805#Comment_52805Thanks! I actually compiled the following code and it works!
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var inputs = jQuery("input[type='text']");
inputs .toArray() .forEach(function(field)
{
new Cleave(field,
{
numeral: true,
numeralThousandsGroupStyle: 'thousand',
prefix: "$"
});
});
jQuery("#"+this.questionId+" input[type='text']").attr('type', 'tel');
});
https://community.qualtrics.com/XMcommunity/discussion/comment/52809#Comment_52809I did just that for the top and bottom question. However, with my code, it is putting a prefix in the 'other' text entry box for the question in between. I do not have any code for the middle question too... It will only let me enter numeric values too.
https://community.qualtrics.com/XMcommunity/discussion/comment/52815#Comment_52815That's because
jQuery("input[type='text']")finds all inputs with type=text on the page. Use
jQuery("#"+this.questionId+" input[type=text]")instead.
https://community.qualtrics.com/XMcommunity/discussion/comment/52816#Comment_52816I honestly cannot thank you enough TomG. Thanks for all the help in the past couple of hours!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.