Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!