Sunday, December 31, 2017

Function to make "get" parameters of URL

A function to make "get" parameters of URL.
    function getquery_build(query,name,value){
        query = query + (query.slice(0, 1) == '?' ? '&'+name+'='+value : '?'+name+'='+value);
        return encodeURI(query);
    }

Usage:
query = "";
query = getquery_build(query, 'index1', 'value1');
query = getquery_build(query, 'index2', 'value2');
query = getquery_build(query, 'index3', 'value3');
query = getquery_build(query, 'index4', 'value4');
console.log(query);

The output:
?index1=value1&index2=value2&index2=value2&index2=value2