Search code examples
javascriptpdf-form

Convert digits into words with JavaScript in PDF Form


When I use the code as mentioned by Salman in Convert digits into words with JavaScript in my PDF form in Foxit Reader - custom calculation script, it does not work and when I see the console it says :

======== Field : calculate ========
[ Line: 00015 { ReferenceError } ] : document is not defined

What I need to modify in this to get it working in PDF form?


Solution

  • You obviously need to change the code

    document.getElementById('number').onkeyup = function () {
        document.getElementById('words').innerHTML = inWords(document.getElementById('number').value);
    };
    

    to the equivalent in foxit

    Something like

    this.getField ("words").value = inWords(this.getField("number").value)
    

    https://www.foxitsoftware.com/blog/how-to-create-forms-that-perform-simple-mathematical-calculations/

    https://developers.foxitsoftware.com/kb/article/javascript-pdf-sdk-java/

    https://www.foxitsoftware.com/blog/how-to-add-javascript-functionality-to-pdf-forms-without-coding/