Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

0

Dont use the # on the document.getElementById.

Use either

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

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda