Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Add Commas to Numeric Response

I'm asking survey respondents how much they spend on certain products - the challenge I'm facing is that any person's spend could be a few thousand or multiple millions.  In order to help the respondent not make a mistake, I want to make my Numeric field add commas when respondents enter a figure with more than 3 digits.  This will help them catch a mistake of 60,000,000 v. 6,000,000 v. 600,000.

Does anyone know how to add this functionality to a numeric response?

Thanks!
asked Oct 8, 2014 by jww04107 (140 points)
This will require some JavaScript code to pop the commas in live (as the respondent is typing). I was searching for some code/examples on the internet but I couldn't get it working myself. Apologies as I'm not a JavaScript expert.

If you want to format the number as you described, you can use the FORMATNUMBER function in Sawtooth.

2 Answers

0 votes
Hi,

You need to do this as a Free Format Question and using Javascript.

Please find below the steps that you need to do:

1) Create a Free Format Question
2) Label this question as "numeric"
3) In variables/Question HTML section:
---- Add
--- Variable type: text (text box)
--- Name: numeric_p1
--- Maximum Characters 11
4) Copy these instructions in HTML ( In variables/Question HTML section):

<script type="text/javascript" src="http://archive.conductiva.com/files/demos/maskedin/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://archive.conductiva.com/files/demos/maskedin/jquery.maskedinput-1.2.2-co.min.js"></script>
<!-- source code version
<script type="text/javascript" src="jquery.maskedinput-1.2.2-co.js"></script>
-->

<input id="numeric_p1" type="text" size="10" maxlength="10" style="width: 80px;"/>
<script type="text/javascript">
jQuery(function($){
    $("#numeric_p1").mask("999,999,999");
});
</script>

IMPORTANT:
1) This question must be completed with all 9 digits else no data recorded and warning appears.
2) This response were saved as text. You will need to recode as number to analyse it.
answered Oct 9, 2014 by Ramon Bronze (785 points)
0 votes
We actually have an article in our knowledge base that walks you through how to do this with JavaScript and a Free Format question: www.sawtoothsoftware.com/1422. Let me know if you have any questions about the article.
answered Oct 9, 2014 by Jeff Forkner Bronze (2,875 points)
...