-1

I have this url

http://www.test.com/home-package/?location=locationA&bed=3&bath=4

and a variable (e.g. $location = "locationB") which holds the value user has selected when they land on the website. They can also change this location from any page they want and the variable will be updated with that location.

What I'm trying to achieve is,

If user is browsing http://www.test.com/home-package/?location=locationA&bed=3&bath=4 and then change the location to 'locationB', I want the url to update to http://www.test.com/home-package/?location=locationB

Hope I have made this clear.

Edit 1: User is selecting location from a dropdown list. <select> is wrapped inside <form> and upon hitting save, the value of location is saved in a session variable.

Thanks.

shutupchigo
  • 703
  • 1
  • 7
  • 19

1 Answers1

0

As I understand the locationB is in HTML input element? Add a onchange listener to the element and redirect user with javascript.

let locationB = getValueFromElement();
window.location.replace("http://www.test.com/home-package/?location="+locationB);
//or
window.location.href = "http://www.test.com/home-package/?location="+locationB;

Read differences between JS redirects.

If the locationB value comes from backend and redirecting in backend is not possible you can also add a hidden element that holds the value and read it with JS.

Cray
  • 2,774
  • 7
  • 22
  • 32