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

131
Visualizações
trying to add form input to url for GET request

How do i go about adding an object onto the end of my url address , at the moment $year is not added to the GET request.

    <input type = "text" id="year">
            <input type = "submit" id="btn">
    
    <script >
    
    document.getElementById("btn").addEventListener("click", function() {
           
            var $year = document.getElementById("year");
            request = new XMLHttpRequest();
            request.open("GET", "https://mudfoot.doc.stu.mmu.ac.uk/node/api/halloffame?year="+$year, true);
            request.send(null);
    
            
        }
        return val;
      }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

use value() after getElementById to get value of that selected element

<input type="text" id="year">
<input type="submit" id="btn">

<script>
    document.getElementById("btn").addEventListener("click", function () {
        var $year = document.getElementById("year").value;
        request = new XMLHttpRequest();
        const reqUrl = "https://mudfoot.doc.stu.mmu.ac.uk/node/api/halloffame?year=" + $year
        console.log("reqUrl: ", reqUrl);  
        request.open("GET", reqUrl, true);
        request.send(null);
    })
</script>

about 4 years ago · Juan Pablo Isaza Relatório

0

Try using:

document.getElementById("btn").addEventListener("click", function()
{
  var $year = document.getElementById("year").value;
  request = new XMLHttpRequest();
  request.open("GET", "https://mudfoot.doc.stu.mmu.ac.uk/node/api/halloffame?year=" + $year, true);
  request.send(null);
}

I think what your problem was is that you weren't getting the value of the input, you were just selecting the element.

You were doing: document.getElementById("year") which gives you the element. But you need to do document.getElementById("year").value which gives you the value of the text box.

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