-6

I want to capture the values which proceeds 'tsid' from the below URL using javascript so in this case it would be '11693' is there a way to do this?

www.foo.co.uk/search/clothing/c:29131/?ashd=AR422&_$ja=tsid:11693%7Cprd:%7Ccat:AR422

Jon O
  • 1
  • 1
  • you mean `11693` right? – vaso123 Oct 02 '17 at 13:00
  • 5
    Possible duplicate of [How can I get query string values in JavaScript?](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – Pete Oct 02 '17 at 13:00
  • Hi Jon, welcome to SO. It is expected that you do a bit of research before posting a question, once you have done some and got stuck with a particular problem, it is expected you post the code and explain exactly where you are stuck. Please take a tour of the [help centre](http://stackoverflow.com/help) to see [how to ask a good question](http://stackoverflow.com/help/how-to-ask). – Pete Oct 02 '17 at 13:02

1 Answers1

-1

You goona use PHP get values and seperate them with this function.

function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
Güney Saramalı
  • 791
  • 1
  • 10
  • 19
  • Where in this question is php mentioned? – Pete Oct 02 '17 at 13:06
  • He is trying to capture the value of tsid from the URL. The proper way to define a var to url is using PHP GET type of var. Please read carefully. – Güney Saramalı Oct 02 '17 at 13:10
  • 1
    **YOU** read the question OP wants to do it using javascript, we don't even know what server side language he is using. Getting it with php will be of no use to them if they are wanting to use it in a javascript variable – Pete Oct 02 '17 at 13:12
  • And the JS code is up in my code god damn. Do you having difficulties with recognize js code and php? He is going to change the url var to proper way which is www.foo.com?tsid=1169&foo=1287312&boo=123213. This is PHP GET type of URL var. and the code above gets it with JSSSSSSS – Güney Saramalı Oct 02 '17 at 13:14