JavaScript   

Update URL param value with the textbox value in realtime using JavaScript

This is an example snippet for updating URL param value using pure JavaScript.  URL param value will be get updated in the realtime as the user starts typing in the textbox.

function updateURLParam() {
	let queryParams = new URLSearchParams(window.location.search);
	let emailVal = document.getElementById("email").value;	
	queryParams.set("email", emailVal); //email is URL param name
	history.replaceState(null, null, "?"+decodeURIComponent(queryParams));
} 

 

<input type="email" id="email" onkeyup="updateURLParam()">
Need a helping hand in fixing your website issues?

If you are facing any problems in implementing these code snippets and tutorials, you can hire us to fix your website issues.

Hire Us