- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 09:16 AM
Hello All,
I am trying to populate 2 variables by concatenating & incrementing 4 different variables using onChange client script based on a Quantity variable.
Variables: A,B,C,D,E,F
A,B,C are reference fields
D is a single line text with default value as '00'.
If the Quantity is 1 then the variable E will be populated as ABC00
If the Quantity is 2 then the variable F should be populated as ABC01, but the script i'm using is populating the variable as ABC1 instead of ABC01.
please let me know where i'm doing mistake.
Script:
var qt = g_form.getValue('a');
var en = g_form.getValue('b');
var eco = g_form.getValue('c');
var it = g_form.getValue('d');
var hn = en + eco + it;
if(qt == 1){
g_form.setValue('e', hn);
}
var it2 = ++it;
var hn2 = en + eco + it2;
if(qt == 2){
g_form.setValue('d', hn);
g_form.setValue('e', hn2);
}
Thanks,
SD
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2019 09:51 AM
If you need to use numbers and store them in a field with padded zeroes, you can write a function like this:
function padWithZeroes(number, len) {
var output = number.toString();
while (output.length < len) {
output = "0" + output;
}
return output;
}
var test = padWithZeroes(13, 5); // test equals "00013"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2019 06:45 AM
You only call padWithZeroes() on the number part (such as it2) and set it to the desired length of the zero-padded string:
var numericPart = padWithZeroes(it2, 2); // turns 2 into "02", 5 into "05", etc.
