function onSubmit() {
var Price1 =parseDecimal(g_form.getValue(‘u_price’)); // Call parseDecimal function
var Price2 =parseDecimal(g_form.getValue(‘u_price_2’));// Call parseDecimal function
var Total = Price1 + Price2 ;
g_form.setValue(‘u_total’,Total);//populate total field by the sum of Price1 and Price2
}
function parseDecimal(d) {
// Remove currency and any potential any undesirable character
d=d.replace(/[a-zA-Z\!\@\#\$\%\^\&\*\(\)\_\+\-\=\{\}\|\[\]\\\:\”\;’\\?\,\/\~\`]/g,””);
// Loop through the currency and replace the comma
while (d.indexOf(“,”) != d.lastIndexOf(“,”))
d=d.replace(/\./,””);
return parseFloat(d);
}