- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2023 05:50 AM - edited 05-16-2023 05:50 AM
Hi All,
I have variable called Cost and it should accept the both decimal values and number. How can i achieve this.
Example :
1.Cost : 100
2. cost : 1000.12345 which should rounded to 100.12
Note : It should accept both numbers and decimal values
I have written the below script.
function onSubmit() {
var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((cs.match(letter))) {
var value = Math.round(cs*100)/100;
//alert(value);
g_form.setValue('cost',value);
} else {
// g_form.addErrorMessage('Add only numerics');
g_form.showErrorBox('cost','Add only numerics');
g_form.submitted = false;
return false;
}
}
It is working fine but there is a java script browser console error is coming which says "cs.match is not a function". How do I avoid this error. Please help!
Thank you in Advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2023 06:03 AM
Try as below-
var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((letter.test(cs))) {
}
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2023 06:03 AM
Try as below-
var cs = g_form.getValue('cost');
var letter = /^[0-9.]+$/;
if ((letter.test(cs))) {
}
Thanks,
Manjusha Bangale