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

245
Visualizações
How to Combine 3 ID's when a button was clicked?

I've try this code


<p>Watch Series Online</p>
<input type="search" id="imdbseries" class="Search" name="" value="" 
placeholder="IMDB ID">
<input type="search" id="season" class="Search" name="" value="" 
placeholder="SEASON">
<input type="search" id="episode" class="Search" name="" value="" 
placeholder="EPISODE">
<button id= "search" onclick="search()" >Watch Now</button>
<script>
function search() {
  var imdbseries = document.getElementById('imdbseriesID','season#',episode#').value
window.location.href = "https://mysiteurl.com/tv.php?imdb="+ imdbseriesID + "&season=" + season# + "&episode=" + episode#;
}
</script>

but fail for 3 ID's..

I want that when I fill the box with IMDB ID:tt9140554 SEASON:1 EPISODE:1

it should go to this EXSACT URL when the button was clicked. https://mysiteurl.com/tv.php?imdb=tt9140554&season=1&episode=1

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Your html

<p>Watch Series Online</p>
<input type="search" id="imdbseries" class="Search" name="" value="" 
placeholder="IMDB ID">
<input type="search" id="season" class="Search" name="" value="" 
placeholder="SEASON">
<input type="search" id="episode" class="Search" name="" value="" 
placeholder="EPISODE">
<button id= "search" onclick="search()" >Watch Now</button>

Your script

function search() {
   // The document.getElementById() takes one Id
   let imdbseries = document.getElementById("imdbseries").value;
   let season = document.getElementById("season").value;
   let episode = document.getElementById("episode").value;

   location.href = `https://mysiteurl.com/tv.php?imdb=${imdbseries}&season=${season}&episode=${episode}`

}
about 4 years ago · Juan Pablo Isaza Relatório

0

Here's the documentation for getElementById. As you can see it accepts only one argument.

An alternative is to use querySelector. (You can tidy up the markup a little by replacing putting the id values in the name attribute, and removing the ids altogether.) Then you can just target elements by their name attributes, grab the values, and then build a string.

(Note: at some point you may want to add some validation to check the input values are valid. For example, both season and episode should both be numbers.)

function search() {

  const imdbseries = document.querySelector('[name="imdbseries"]').value;
  const season = document.querySelector('[name="season"]').value;
  const episode = document.querySelector('[name="episode"]').value;

  console.log(`https://mysiteurl.com/tv.php?imdb=${imdbseries}&season=${season}&episode=${episode}`);

}
<input type="search" name="imdbseries" placeholder="IMDB ID" />
<input type="search" name="season" placeholder="SEASON" />
<input type="search" name="episode" placeholder="EPISODE" />
<button onclick="search()" >Watch Now</button>

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