CP9 JavaScript and Retrieving Numeric Values
I have a slide with a text entry field for entering the last 4 digits of their telephone number. I need to have an edit which makes sure that they entered only numbers and that they entered all 4 digits.
When I was using Captivate 8, I was able to use the following JavaScript code to get and check the variable information which had been entered on the screen for various user variables:
function getTheCourseVariable(variableName) {
var holdValue = null;
if (window.cpAPIInterface) {
holdValue = window.cpAPIInterface.getVariableValue(variableName);
} else {
var cpFlash = document.Captivate;
if (cpFlash) {
holdValue = cpFlash.cpEIGetValue('m_VarHandle.' + variableName);
} else {
holdValue = cp.variablesManager.getVariableValue(variableName);
}
}
return holdValue;
}
This would return the value of this 4 position "phone" field, with leading zeros and everything. I was then able to check the length of the variable to see if they enter all 4 positions (such as "0001").
Since I started using Captivate 9, if the student enters "0001" in the field, when I use this function, it returns a value 1 with a length of 1 (ie: it removes all leading zeros). This makes it impossible for me to check the length for 4 positions.
What is really strange is when I displayed this value on a later screen (if I let it go past my edits), the value does displays as "0001".
One time I entered "123" and before leaving that slide set the value of this field in JavaScript to "0123", but on the later screen this user variable displayed the same way that it did as I entered it on the previous screen ("123"), like it was ignoring the fact that I had used the Setter method of the Common JS Interface to change it's value.
This happens no matter if I have the field defined as Numbers under the More Options buttons or the "All" option. They have a Maximum Length value on the More Options sub-menu. Is there some type of "Minimum Length" that they can have which will leave the leading zeros of a user variable, even if the values are numeric?
I just need to make sure that this field is present, all numeric and all 4 positions are filled in. Is there some way to do this within Captivate?
Is there a special call or parameter that I can use so that this value comes back to me as text, versus a truncated numeric value?
Using JavaScript, I have even tried "padding" the front with zeros in JavaScript, but when I set the variable and get it again, the leading zeros are truncated again. I even tried padding like: "T001" and it remained "T001" (with a length of 4), but when I tried it with "0001" it always came back as 1 with a length of 1.
Right now it looks like I might have to go back to using Captivate 8 until this problem is solved.
Any help or advice would be greatly appreciated.
Thank you for your time.
Randy