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

144
Vistas
How to get and set time input value?

I have an input with type "time".

<input type="time" id="time1" value="18:00">


Now, if I try to get the default value via console. I'm getting :

console.log(document.getElementById("#time1").value())
VM250:1 Uncaught TypeError: Cannot read properties of null (reading 'value')
    at <anonymous>:1:47

Can you give me some suggestions how to set the value of the time input, if I'm getting a string value from an object.

For example: "06:00 AM"

I know that it will not accept that string since there's a unexpected character in it.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Dont use the # on the document.getElementById.

Use either

document.getElementById("time1");
//-- or --
document.querySelector("#time1");
about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of using value(), use value

console.log(document.getElementById("time1").value);
<input type="time" name="car" id="time1" value="18:00">

about 4 years ago · Juan Pablo Isaza Denunciar

0

There are 2 errors in your code.

1 - No need to use # when you use getElementById. Because we are already telling browser to get by Id. However you would need # if you are using querySelector.

  1. value is not a function.

So the code should be

console.log(document.getElementById("time1").value)

Reference: https://www.w3schools.com/jsref/prop_text_value.asp

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