Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda