-1

I am a newbie to web development.

I have fixed initial url with params.

@url = http://localhost:3000/home/results?utf8=%E2%9C%93&what=&where=&commit=search&property_for=

Now, i want to add params to this url individually, like

@price = something
@bedrooms = something

final url = @url + @price + @bedrooms

How can i get this using javascript?? Can anyone provide reference code or link to understand

Zeina
  • 1,573
  • 2
  • 24
  • 34
Ashwin Yaprala
  • 2,737
  • 2
  • 24
  • 56
  • Is this for the current page that is loaded? Or are you trying to manipulate a target url to be used for AJAX or as an HRef? – Ravi Y Jan 15 '13 at 07:53
  • http://stackoverflow.com/questions/6953944/how-to-add-parameters-to-a-url-that-already-contains-other-parameters-and-maybe & http://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript – palaѕн Jan 15 '13 at 07:54
  • 1
    `var url = window.location.href +'&price='+price+'&bedrooms='+bedrooms;` – Ohgodwhy Jan 15 '13 at 07:54
  • need to explain where javascript will get the url value shown from, and where the new parameters will come from within the page.. and what it will do with the revised url – charlietfl Jan 15 '13 at 07:55
  • No ajax, the parameter will come from within the page. By using window.locatio.href, the parameters getting added continously to the url, presently my url is working with window.location += '&price_min=' + PropertyPriceFilter.min + '&price_max=' + PropertyPriceFilter.max; – Ashwin Yaprala Jan 15 '13 at 08:03
  • I want to change above things – Ashwin Yaprala Jan 15 '13 at 08:06

1 Answers1

0

try this function

function getURL(qs) {
   var href = document.location.href;
   if (href.indexOf('?') >= 0) href = href.substring(0, href.indexOf('?'));
   if (href.indexOf('#') >= 0) {
       href = href.substring(0, href.indexOf('#'));
   }
   if (qs) {
      document.location.href = href + (qs === true ? "" : ('?' + qs)) + document.location.hash;
}
else
    return href + document.location.hash;
    return 1;
}

you can pass true, if you dont want any querystring and pass "id=somevalue" to this function to get url along with querystring

Rahul
  • 928
  • 5
  • 8