1

i have problem when try to delete parameter url from js, because i'm using searchParams.delete( ) but it's not working as i expected. actually i just want to delete one params here this is &ProductFilter%5Bstatus%5D%5B%5D=3 from url http://localhost:8080/product/index?q=&ProductFilter%5Border%5D=&ProductFilter%5Bstatus%5D=&ProductFilter%5Bstatus%5D%5B%5D=2&ProductFilter%5Bstatus%5D%5B%5D=3

here my code in html to send param that i get from database

<span class="badge"> Available &nbsp;<a onclick = "deleteTag(\'ProductFilter[status][]\', '.$value.')"><iconify-icon icon="ph:x-light" style="color: white;" width="16" height="16"></iconify-icon></a></span>

and here my js code to delete the tag html above

   async function deleteTag(paramName,idval) {

      var url = new URL(window.location.href)
      var searchParams = new URLSearchParams(url.search)

      var parameterValues = searchParams.getAll(paramName)
        parameterValues.forEach(value => {
          searchParams.delete(paramName, idval)
        })
      url.search = searchParams.toString()

      window.location.href = url.search;

    }

and the result always delete all params in ProductFilter[status] so, anybody can help me?

ADyson
  • 57,178
  • 14
  • 51
  • 63
chiper4
  • 303
  • 5
  • 18

0 Answers0