jquery - Javascript to show any/all query values in the URL -


i working on document list filter menu pair down listing via query strings. want display current query values in designated div, have working. problem have have each category individually coded in js, causes "undefined" value display if there no query category.

i want display values represented in query. have been trying create array, js spotty @ best , has been kludged-together multiple sources. suggestions? here current js:

 function getqueryvariable(variable) {     try{             q = location.search.substring(1);             v = q.split("&");             for( var = 0; < v.length; i++ ){                 p = v[i].split("=");                 if( p[0] == variable ){                     if( p[1].indexof('_') != -1 ){                         n = [];                         for( var j = 0; j < p[1].split('_').length; j++ ){                             n.push(p[1].split('_')[j]);                         }                         str = "";                         for( var k = 0; k < n.length; k++ ){                             str += n[k] + ' ';                         }                         return str.trim();                     }                     else{                         return p[1];                     }                 }             }         }         catch (e){             console.log(e);         } }     if(document.location.search.length) { // query string exists $p( "div#filtercontainer" ).html(           "<div class='littype'><ul class='ct-list'><li class='ct-list-elem'>"          +getqueryvariable('application')          +"</li>"+          "<li class='ct-list-elem'>"          +getqueryvariable('year')          +"</li>"+          "<li class='ct-list-elem'>"          +getqueryvariable('industry')+          "</li>"+          "<li class='ct-list-elem'>"          +getqueryvariable('literature_type')          +           "</li></ul></div>" ); } else { // no query string exists $p( "div#filtercontainer" ).html(           "no filters being applied." ); } 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -