【问题标题】:Leading zeros from PDF field to javascript variable从 PDF 字段到 javascript 变量的前导零
【发布时间】:2014-04-25 23:42:35
【问题描述】:

希望这是提出这个问题的正确地方。我对 javascript 几乎是全新的,但是看到它与我编写的其他语言的相似之处,到目前为止它非常容易 - 直到现在。

我正在为用户填写完网格时单击的按钮编写脚本。该脚本遍历网格中的字段,获取信息并生成一封电子邮件。然后它会发送一个带有生成信息的 mailto: 命令,这比用户自己键入电子邮件要容易得多。我遇到的问题是,字段的标准之一是税号,有时可以从零开始,当我将该字段值分配给变量时,它会丢弃前导零。如何让 javascript 保持这个前导零?我尝试在开头声明一个带有“”的变量,以尝试强制它将变量识别为字符串,但这似乎不起作用。

这是我的代码:

if(this.getField("ProviderOne").value != "")
{
    // This is the form return email. Its hardcoded
    // so that the form is always returned to the same address
    var cToAddr = "blank@blank.org";

    // First, get the client CC email address
    var cCCAddr = "blank@blank.com";



    var pOneTaxID = new String(this.getField("ProviderOneTaxID").value); //tring to force string value

    // Set the subject and body text for the email message
    var ProviderOne = this.getField("ProviderOne").value + " NPI:" + this.getField("ProviderOneNPI").value + " Tax ID:" + pOneTaxID;

    var ProviderTwo = this.getField("ProviderTwo").value + " NPI:" + this.getField("ProviderTwoNPI").value + " Tax ID:" + this.getField("ProviderTwoTaxID").value;

    var ProviderThree = this.getField("ProviderThree").value + " NPI:" + this.getField("ProviderThreeNPI").value + " Tax ID:" + this.getField("ProviderThreeTaxID").value;

    var ProviderFour = this.getField("ProviderFour").value + " NPI:" + this.getField("ProviderFourNPI").value + " Tax ID:" + this.getField("ProviderFourTaxID").value;

    var ProviderFive = this.getField("ProviderFive").value + " NPI:" + this.getField("ProviderFiveNPI").value + " Tax ID:" + this.getField("ProviderFiveTaxID").value;

    var cSubLine = this.getField("ProviderOne").value + " ERA setup for [BLANK]";

    var cBody = "To [BLANK], \n \nPlease enroll the following providers to receive [BLANK] through [BLANK] under [BLANK]: \n \n";

    if(this.getField("ProviderOne").value != "")
    cBody += "1. " + ProviderOne + "\n";

    if(this.getField("ProviderTwo").value != "")
    cBody += "2. " + ProviderTwo + "\n";

    if(this.getField("ProviderThree").value != "")
    cBody += "3. " + ProviderThree + "\n";

    if(this.getField("ProviderFour").value != "")
    cBody += "4. " + ProviderFour + "\n";

    if(this.getField("ProviderFive").value != "")
    cBody += "4. " + ProviderFive + "\n";

    cBody += "\n Thank you,\n" + this.getField("ProviderOne").value;

    app.mailMsg({bUI: true, cTo: cToAddr, cCc: cCCAddr, cBCc: "", cSubject: cSubLine, cMsg: cBody});
}
else
{
    app.alert("Please enter at least one payer into the grid above.", 1, 0, "Unfilled Form");
    this.getField("ProviderOne").setFocus();
}

非常感谢您花时间阅读本文,如果您能帮助我找到解决方案,则更感谢您。

-安德鲁

【问题讨论】:

    标签: javascript pdf


    【解决方案1】:

    想通了。我没有使用 getField("FieldName").value 来获取值,而是使用 .valueAsString 来获取它。如果有人在路上发现它,希望这很有用。

    【讨论】:

    • 这是从字段中获取前导零的标准方法。但是,您可能要做好准备,JavaScript 仍然可以将其转换为数字。为了防止这种情况,您将添加 ' event.value = " " + event.value ; ' 到相关字段的 Validate 事件。
    猜你喜欢
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 2021-09-30
    相关资源
    最近更新 更多