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

318
Views
Obtenga el valor del tipo de entrada = fecha como una cadena

Quiero extraer el valor del campo de fecha, pero no funciona. Agrego la entrada de esta manera:

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

Así es como traté de recibir el valor:

 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);

Entonces, quiero obtener el valor de la entrada como una cadena, usando JavaScript puro, porque luego se usará para completar el documento.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Prueba esto

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

0

No hay suficiente información para resolver el problema, por lo que solo puedo suponer que probablemente esté insertando su variable en el DOM de manera incorrecta. Si llamo a document.body.append(question0) , solo se muestra el texto y no las etiquetas. Intente mover el contenido de la variable question0 a su archivo html, luego agregue el controlador onchange a su entrada y también modifique su archivo .js como se muestra a continuación

 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>

Si desea desesperadamente crear su HTML dentro de Javascript, debe hacer esto de esta manera:

 // 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 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!