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

180
Visualizações
how to pass multiple params in url through javascript

I have an if-else condition in javascript. In every else condition I want to pass a parameter id with its value in url on & basis like in first else condition code passed a value 5 with id variable.

http://localhost/cah/blank.php?id=5

in second condition

http://localhost/cah/blank.php?id=5&id=9

and so on. Likewise I can have multiple conditions in which I have to pass different values of id in url. how can it be done? Either by storing them all in an array or pass values in url on & basis but without refreshing page.

var count=0;
var counts=0;

function check() {
    var a = document.getElementById("div1") ;
    var b = document.getElementById('div1').getAttribute('value');

    if (a.textContent==b){
        count++;
        var p1=document.getElementById('cnt');
        p1.value=count;
        a.style.color = "green";
    }
    else { 
        counts++;
        a.style.color = "Red";
        window.history.pushState("object or string", "Title", "./blank.php?id=<? echo $id;?>");
        $('#d<? echo $d3++;?>').addClass('disabled');
    }
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Use array-style names for the parameters:

http://localhost/cah/blank.php?id[]=5&id[]=9

PHP will then make $_GET['id'] return an array of all the parameters.

var ids = [5, 9];
var id_params = ids.map(function(id) {
  return 'id[]=' + id;
}).join('&');
var url = 'http://localhost/cah/blank.php?' + id_params;
console.log(url);

In PHP it would be:

<?php
$ids = array(5, 9);
$id_params = implode('&', array_map(function($id) {
    return 'id[]=' . $id;
}, $ids));
?>
window.history.pushState("object or string", "Title", "./blank.php?<?php echo $id_params;?>");
over 4 years ago · Santiago Trujillo 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