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

127
Views
Generando valor de entrada en 2 entradas llenas anteriores

Estoy tratando de generar un valor de entrada basado en 2 valores de entrada anteriores que completó el usuario. Primero es un nombre, el segundo es una fecha. Ahora necesito concatenar y formatear estos 2 valores y configurarlos para otra entrada.

Esto es lo que ya se me ocurrió:

  1. Oyente de eventos para la primera entrada: Nombre
  2. Dar formato al valor del Nombre
  3. Oyente de eventos para la segunda entrada: Fecha
  4. Dar formato al valor de fecha
  5. Concat estos 2 valores
  6. Establecer el valor de concat en la tercera entrada

El código que tengo hasta ahora:

 window.onload = function () { /* event listener for first input: Name */ document.getElementById('input_7_1').addEventListener('change', formatTitle); /* function to format the name value properly */ function formatTitle(){ document.getElementById('input_7_1').addEventListener("input", function(){ var title = document.getElementById('input_7_1').value; var formatTitle = title.replace(/\s+/g, ''); }); } /* event listener for second input: Date */ document.getElementById('input_7_3').addEventListener('change', formatDate); /* function to format the date value properly */ function formatDate(){ document.getElementById('input_7_3').addEventListener("input", function(){ var date = document.getElementById('input_7_3').value.replace(/\//g, ''); var formatDate = date.slice(0, -4); }); } /* concat both values in a variable */ var studentNummer = formatTitle.concat(formatDate); /* set value in the third input: Studentnummer */ function generateInput(){ document.getElementById('input_7_9').value = studentNummer; } }

Estoy casi allí por mi sentimiento. ¿Que me estoy perdiendo aqui?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Simplifiqué su código y lo hice mucho más comprensible. Prueba esto

 window.onload = function () { let studentNoField = document.getElementById('input_7_9'); let enteredDetails = {name: '', date: ''}; /* set value in the third input: Studentnummer */ function generateInput(){ let studentNumber = Object.values(enteredDetails).join(''); studentNoField.value = studentNumber; } /* event listener for first input: Name */ document.getElementById('input_7_1').addEventListener('input', function(event){ enteredDetails.name = event.target.value.replace(/\s+/g, ''); generateInput(); }); /* event listener for second input: Date */ document.getElementById('input_7_3').addEventListener('input', function(event){ enteredDetails.date = event.target.value.slice(0, -4); generateInput(); }); }
about 4 years ago · Juan Pablo Isaza 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!