-1

i have a url that has several parameters, and i want to replace them using JQuery (not javascript).

var str = "http://example.com/index.php?color=red&size=large&quantity=5";
var newQty = 10;

How can i change the quantity using JQuery ONLY if quantity exists as a parameter? How can i change a parameter that isn't at the end of the query string, such as size=large?

I prefer to use regex and .replace function, if anyone can help me with the proper code please... something like this.

var newStr = str.replace(REGEX, "quantity="+newQty);

Kuku Bhai
  • 11
  • 6
  • do some searching...there are lots of posts here and small url scripts and libraries on web. Start here http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – charlietfl Jul 10 '16 at 23:31

1 Answers1

0
var REGEX = /quantity\=[0-9]+/;
raduation
  • 792
  • 5
  • 11
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – HiDeoo Jul 10 '16 at 21:58