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

325
Vistas
Get value of input type=date as a string

I want to extract the value from date field, but it doesn't work. I add the input this way:

var question0  = "<div id='0'><p>Please, enter the date: </p><br>" 
                       + "<input type=\"date\" id=\'contractdate\'></input><br></div>";

Here is how I tried to receive the value:

var text_Contract_Date     = document.getElementById('contractdate').value;
//tried the code below, but didn't work
// var text_Contract_Date  = document.getElementById('contractdate').valueAsDate;
// var text_Contract_Date  = new Date(document.getElementById('contractdate').valueAsDate);

So, I want to get the value from input as a string, using pure JavaScript, because then it will be used to fill in the document.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Try this

var dateEntered = new Date(text_Contract_Date);
about 4 years ago · Santiago Trujillo Denunciar

0

There is not enough information to resolve the issue, so I can only guess that you are probably inserting your variable into the DOM the wrong way. If I call document.body.append(question0), only text is shown and not the tags. Try moving content of question0 variable to your html file, then add onchange handler to your input, and also modify your .js file like below

function handleChange(event){
  // here you can do whatever you want with the value of the input
  alert(event.target.value)
}
<input type="date" id='contractdate' onchange="handleChange(event)"></input>

If you desperately want to create your HTML inside of Javascript, you have to do this like this:

// create div and assign id to it
const myDiv = document.createElement("div")
myDiv.id = '0'

// create p and set its contents
const myP = document.createElement("p")
p.textContent = "Please, enter the date: "

// create input, assign id to it and set its type to date
const myInput = document.createElement("input")
myInput.id = 'contractdate'
myInput.type = "date"

// put everything in your document
myDiv.appendChild(myP)
myDiv.appendChild(myInput)
document.body.appendChild(myDiv)
about 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