I have been unable to successfully have a comma insert into a current number. Could this by chance have anything to do with how the file is published? Does the file have to be published HTML5 ?
I created the text entry field as in the examples. It's still not pulling the comma over.
My code is below. The number field where the digits are entered is called "NumberEntry" and the Text box to display the number with commas is "Answer".
I'm unable to pull up the java console. I'm checking with IT now. I did replace the ' with ;
and I used a new name for the numericEntry called Entrynumber.
var player = GetPlayer(); var Answer = player.GetVar(“Entrynumber”); Answer = numberWithCommas(Answer); player.SetVar(“Answer”,Answer); function numberWithCommas(x) { var parts = x.toString().split(“.”); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, “,”); return parts.join(“.”); }
I was testing but I could see how it may have been confusing so I changed it for this discussion. I'm doing a basic test right now. Waiting to hear from IT to see if something is blocked.
You have an error in the user.js file so something is wrong in the javascript in your course.
I cannot see if you are referencing the correct variables in the file, but that is a typical error, any error will stop the apprising of the file and stop the javascript working. Do you have any other javascript in the file?
I couldn't find much wrong with it so swapped the code for one in a project I have that I know works:
var player = GetPlayer(); var JSAnswer = player.GetVar("SLNumber"); JSAnswer = numberWithCommas(JSAnswer); player.SetVar("SLAnswer",JSAnswer); function numberWithCommas(x) { var parts = x.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); return parts.join("."); }
I am not sure, not had too long to look at this, but I don't understand why you convert the number to a string and sending to a numeric value. I will have a look tomorrow if I can find some time. It was working so must be something that has changed.
29 Replies
In a number entry field you cannot enter any commas only a decimal point
I created the text entry field as in the examples. It's still not pulling the comma over.
My code is below. The number field where the digits are entered is called "NumberEntry" and the Text box to display the number with commas is "Answer".
var player = GetPlayer();
var Answer = player.GetVar(“NumbericEntry”);
Answer = numberWithCommas(Answer)’
player.SetVar(“Answer”,Answer);
function numberWithCommas(x) {
var parts = x.toString().split(“.”);
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, “,”);
return parts.join(“.”);
}
I have a button set up to execute the trigger
I think your numericEntry variable is incorrectly named and you need to replace a ' with a ; on line 3
Do you get any javascript errors in the console?
I'm unable to pull up the java console. I'm checking with IT now. I did replace the ' with ;
and I used a new name for the numericEntry called Entrynumber.
var player = GetPlayer();
var Answer = player.GetVar(“Entrynumber”);
Answer = numberWithCommas(Answer);
player.SetVar(“Answer”,Answer);
function numberWithCommas(x) {
var parts = x.toString().split(“.”);
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, “,”);
return parts.join(“.”);
}
are you referencing the correct variables, without testing it, it looks OK
I was testing but I could see how it may have been confusing so I changed it for this discussion. I'm doing a basic test right now. Waiting to hear from IT to see if something is blocked.
Phil,
This is what I get on the javascript error console.
Any ideas why I'm getting this? I could send over the file if that helps.
You have an error in the user.js file so something is wrong in the javascript in your course.
I cannot see if you are referencing the correct variables in the file, but that is a typical error, any error will stop the apprising of the file and stop the javascript working. Do you have any other javascript in the file?
I do have another. I'll remove that one and see if that works.
I deleted all but the one very simple test file and attached is the error.
The reference name is correct. I kept it simple for the test.
It seems like adding commas should not be so hard. :|
I do appreciate your help!
Thank you,
Maria
Can you upload the slide or email it to me and I will fix it for you?
Sent from my iPhone
If you can't access this, I can email it to you.
Thanks so very much!!!
I really need to look at the storyline file and not the published output
Here it is.
Thank you again so, so very much!
We can't tell you how much we appreciate your help solving this problem.
We'd like to present the later this week and would love for the numbers to have the commas.
Much appreciated!
Maria
The test slide is slide 1.4
I couldn't find much wrong with it so swapped the code for one in a project I have that I know works:
var player = GetPlayer(); var JSAnswer = player.GetVar("SLNumber"); JSAnswer = numberWithCommas(JSAnswer); player.SetVar("SLAnswer",JSAnswer); function numberWithCommas(x) { var parts = x.toString().split("."); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); return parts.join("."); }
Here is the example https://360.articulate.com/review/content/cb220183-38b3-4e4d-9ef0-945aeaeaaa9a/review
Because it is in SL2 (I don't have installed anymore), and I opened in 360 you need to do a few things.
Change the code to work when user clicks the button rather than timeline start.
Change Numberentry to SLNumber change text variable to SLAnswer
should then work.
Phil,
I can't tell you how much we appreciate your help! It worked :D
This is what I use for commas in one line. It seems to be working and you don't need to fiddle with many lines.
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
https://www.rabbitoreg.com/examples/p99/#/lessons/jPQVjOqI1uW6CqeP_rwsYBzupFRk43Ve
Thanks Zsolt
Sent from my iPhone
Hi Phil,
The project is well kind of complete (it works sometimes) but the rounding doesn't always work on slide 1.11 "Base Layer" and slide 1.12.
Do you know what could be happening? I've included the file.
Would need the storyline slide to have a look
They are attached. We would present this to clients.
Slides 1.11 and 1.12
I am not sure, not had too long to look at this, but I don't understand why you convert the number to a string and sending to a numeric value. I will have a look tomorrow if I can find some time. It was working so must be something that has changed.
This discussion is closed. You can start a new discussion or contact Articulate Support.