I am using EVOPDF to generate pdf using code of cshtml in an mvc application. I have a 4 textboxes for amount onto my cshtml file and 1 more text box is for TotalAmount. Total amount's value will be sum of the all 4 textboxes' value. I have achieved this using below c# code
pdfDocument.Form.Fields["qyt1"].Action = new PdfActionJavaScript(JaveScriptfunctionForCurrentYear())
private string JaveScriptfunctionForCurrentYear() //C# method, returning js code as string to calcuate Total amount
{
return " this.getField('totqyt').value = (parseInt((this.getField('qyt1').value=='')?0:this.getField('qyt1').value) + parseInt((this.getField('qyt2').value=='')?0:this.getField('qyt2').value) + parseInt((this.getField('qyt3').value=='')?0:this.getField('qyt3').value)+ parseInt((this.getField('qyt4').value=='')?0:this.getField('qyt4').value));";
}
Calculation of Total is working fine for only numeric values. Above code is breaking when user inputs numeric values with comma. So, to handle this situation, i modified my method to calcuate Total amount like below. But below code, is not working for number without comma.
private string JaveScriptfunctionForCurrentYear() //C# method, returning js code as string
{
return " this.getField('totqyt').value = " +
" + parseInt((this.getField('qyt2').value =='')?0:this.getField('qyt2').value.replace(',','')) " +
" + parseInt((this.getField('qyt2').value =='')?0:this.getField('qyt2').value.replace(',','')) " +
" + parseInt((this.getField('qyt3').value =='')?0:this.getField('qyt3').value.replace(',',''))" +
" + parseInt((this.getField('qyt4').value =='')?0:this.getField('qyt4').value.replace(',',''))";
}
Apart from that, user can also input decimal values, that should also be summed up into Total Amount.
So, guide me how to calculate Total Amount if user inputs numeric values with comma as wel decimal values. I want to prevent user from inputting any other character that might break the calculation.