Hi there,
I am trying to amend some javascript to replace numbers entered in an array (texts) question with the same numbers but formatted to include commas for thousands. I have taken code from
here
for referencing the question answer, and
here
for replacing the entry with the same number formatted. Unfortunately, I can't get it to produce the desired result. Any ideas? My code looks like this...
Code:
<script type='text/javascript' charset='utf-8'>
$( document ).ready( function() {
var this_surveyId='{SID}';
var this_groupId='{self.gid}';
var this_quesitonId='{self.qid}';
var this_self='{self.sgqa}';
var my_targetTextBox='#answer' + this_self;
// Operate for its intrinsic value:
$( my_targetTextBox ).blur( function() {
$( this ).val( $( this ).val().replace(/\B(?=(\d{3})+(?!\d))/g, ",") );
});
});
</script>
Regards,
Will
Last edit: 8 years 5 months ago by Baarceri_122875. Reason: Typos
This is a very hard thing to do. We tried this to make this work in LimeSurvey as a core function but gave up on it.
The main problem is that there is no way to correctly format the number while typing, especially if you have decimals, because it would require that you know the full number in advance.
My advice: Don't waste your time on that one - you will regret it.