Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Javascript: How to compare against substring in PDF forms?

I am trying to use some Javascript in a PDF form. As an example, let's say I have two fields: let's call them TextField1 and TextField2.

These fields can be used independently, but when TextField1 has a certain value, I'd like TextField2 prefilled.

This works fine (triggered onBlur, not that it matters):

var f = this.getField("TextField1");
var g = this.getField("TextField2");

if (f.value == "123") {g.value = "foobar";}

My problem is this: How can I compare against a substring of f? I'd like the action to trigger when the first char of f equals "1", but

if (f.value.substr(0,1) == "1") { … } 

or similar have not worked.

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try to make a string instance from value.

You can use one of the following methods:

var fStr = f.value + '';
var fStr = String(f.value);

and then try to test fStr in a manner you mentioned above: fStr.substr(0,1) === 'a'

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!