Trying to do the following:
1) User is on page: https://www.example.net/value1/value2/value3/catid,xy somepages have value of catid=xy/value4/value5/value6/ - Category page 
2) User clicks on LINK <a href="https://www.example.net/index.php?valuexyz&(******input value of cat id on the page im on now***)"></a>
I would like user on page catid,xy to click LINK and the URL string of catid,ab in the href to be automatically replaced with xy onclick. 
Or redirected to page: https://www.example.net/index.php?valuexyz&catid,xy on click. 
Simply put I want to have the URL string of catid change based on current page cat id. 
      <script>
        if (window.location.href.indexOf("catid") > -1) {
        {
        document.getElementById("PostingAd").onclick HERE == window.location.href = 'https://www.example.net/index.php?value1value2value3&.catid';
        }</script>
I don't know how to include catid as it keeps changing on every page
NOTE: CATID is not necessarily xy or 12 or xyz it can be 1029 or 123 or hello etc.... also... Catid can be in format of "catid=" and "catid,"
UPDATE TO BE MORE CLEAR
they all have a cat id all i am asking is if im on URL 1 and i click on BUTTON x the button will direct me (the guy browsing on URL 1 = "www.example.com/blblblblblblblsaomasmadkasmdkfsdfsm/VALUE/slkfmsdlkfnlskdf" ) to URL b which is (www.example.com/kmfmksafmdalkf?dslf/VALUE/" for value to change based on url i am on
 
    