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

148
Visualizações
The getElementByID isnt showing the value

PLeaseHelp. it wont show the Value, even for form authentication, to get username & password values,I was trying the same methods.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=<device-width>,initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<h1 id="result">Selected movie is </h1>

    <select id="movie" onchange="showmovie()">
        <option value="Spiderman">Spiderman</option>
        <option value="Spiderman2">Spiderman2</option>
        <option value="Spiderman3">Spiderman3</option>

    </select>
</body>
</html>

<script>
    var movie = document.getElementById("movie").value

    function showmovie(){
        alert("Changed")
       document.getElementById("result").innerHTML="Movie chosen is"+movie
    }
</script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try with this function showmovie

 <script>
    function showmovie() {
        //Selected option
        var selectedMovie = document.getElementById("movie").value;
        document.getElementById("result").innerHTML = "Movie chosen is " + selectedMovie;
    }
</script>
about 4 years ago · Juan Pablo Isaza Relatório

0

The issue here is because of the line var movie = document.getElementById("movie").value being executed just one time at the beginning (you could verify that adding console.log(movie); just after the movie variable declaration)

(movie stores then the value 'Spierdaman') and it never executes again with the calls for showmovie() function, so you could just move the movie declaration line above inside the function so it executes each time the action occurs and then having the good values.

Other details : To have a compliant code i suggest moving the script bloc to part just before and dont forget to add semicolons ';' at the end of each line ! + Better approach would be to use an eventListener as suggested by @T.J. Crowder in comments section above

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