Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda