0

The current url

   http://www.example.com/search/?accommodation=1&venue=&seating=2&min=&max=&feature_list=7|8|9

Is there a way in jquery how can i grab my url which is this one above.... and the feature_list parameter change its value (7|8|9) to something like 8|9|10 ?

I dont need to change the URL header, just I want to link this output to an HREF..

This is what I want to achieve from the current URL.

<a href="http://www.example.com/search/?accommodation=1&venue=&seating=2&min=&max=&feature_list=8|9|10">Link</a>

I am using this as a filtering system...

This is a dynamic url so 7|8|9 changes all the time...

BoqBoq
  • 4,564
  • 5
  • 23
  • 29
  • elclanrs got the answer. If you want to do more "advanced" query parameter operations, you could try this plugin: [link](http://archive.plugins.jquery.com/project/query-object) - which provide some great tools for editing, adinng parameters :) – Marco Johannesen Apr 16 '12 at 09:06
  • its a good idea though I am trying to find a way how to regex a particular parameter, but cannot :( – BoqBoq Apr 16 '12 at 09:10
  • See [this](http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript) .. But the Query plugin makes it much easir for you to get/set the parameters :) – Marco Johannesen Apr 16 '12 at 09:25

3 Answers3

2
var url = window.location.href.replace('7|8|9', '8|9|10'),
    $link = $('<a href="'+ url +'">Link</a>');
elclanrs
  • 92,861
  • 21
  • 134
  • 171
  • since the url is dynamic I cannot just replace 789 with 8910... because this changes all the time... maybe i need some kid of regex for the parameter ? – BoqBoq Apr 16 '12 at 09:05
  • @MRR, maybe you need to polish your question. – Alexander Apr 16 '12 at 09:07
1

maybe not the best solution, but..

var urla = window.location.search.replace('?','').split('&');

$.each(urla, function(j,v)
{
  v=v.split('=');

  if(v[0]=='feature_list')
  {
    var ft=parseInt(v[1].replace(/.*\|/, ''));
    var fts=[];

    for(var i=ft-1; i<ft+2; i++)
      fts.push(i);

    urla[j]=v[0]+'='+(fts.join(','));
  }  
});

urla = '?'+urla.join('&');
$link = $('<a/>',{'href':urla}).text('Link');
flienteen
  • 234
  • 5
  • 13
0
  query = 'feature_list'    
  query = query.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var expr = "[\\?&]"+query+"=([^&#]*)";
        var regex = new RegExp( expr );
        var results = regex.exec( window.location.href );
        if( results !== null ) {
            return  results[1];
            return   decodeURIComponent(results[1].replace(/\+/g, " "));
        } else {
            return   false;
        }

This function i found will return the value of a certain parameter given at the top

and then used elclanrs solution and did

 url = window.location.href.replace(ans, '8|9|10'),
 window.location.href = url;
BoqBoq
  • 4,564
  • 5
  • 23
  • 29