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

113
Vistas
how to return new input value

i would like to replace my old input value (ancien_tel) by (nouveau_tel) to reformat my phone number on blur i missing something to return the value into my input text box.

<!DOCTYPE html>
<html>

<head>
    <title>Page Title</title>
    <meta charset="UTF-8">
    <script>
        function reformatter() {
            var ancien_tel = document.querySelector("#telephone").value;

            var nouveau_tel = "(" + ancien_tel.substring(0, 3) + ") " + ancien_tel.substring(3, 6) + "-" + ancien_tel.substring(6).value;
            ancien_tel = nouveau_tel;

        }   
    </script>
</head>

<body>
    Telephone:<br>
    <input type="text" id="telephone" onblur="reformatter()" maxlength="10">

</body>

</html>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Instead of doing

ancien_tel = nouveau_tel

, do:

document.querySelector('#telephone').value = nouveau_tel

ancien_tel's value is copied from the #telephone element's value, it does not refer to what's inside the #telephone element. A bit less verbose code could be something like:

function reformatter() {
  const telephone = document.querySelector("#telephone");

  const ancien_tel = telephone.value;
  const nouveau_tel = "(" + ancien_tel.substring(0, 3) + ") " + ancien_tel.substring(3, 6) + "-" + ancien_tel.substring(6).value;
  telephone.value = nouveau_tel;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

All you need to change the reformatter function

function reformatter() {
        var ancien_tel = document.querySelector("#telephone").value;

        var nouveau_tel =
          "(" +
          ancien_tel.substring(0, 3) +
          ") " +
          ancien_tel.substring(3, 6) +
          "-" +
          ancien_tel.substring(6);

        document.querySelector("#telephone").value = nouveau_tel;
}
about 4 years ago · Juan Pablo Isaza 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