Using JS to get a variable from URL and populate a text box with a first name.
Code below works well, but if the variable has spaces it will insert %20 in the text box. Looking for a way to replace "%20" with " ".
Example: link.com/?fn=Mary%20Ellen
<script type="text/javascript">
function populatefirst() {
var varSection = window.location.search.substr(1);
var varArray = varSection.split("&");
for(var v=0; v<varArray.length; v++) {
var keyValueArray = varArray[v].split("=");
if(keyValueArray[0]=="fn") {
varValue=keyValueArray[1];
document.getElementById("first_name").value=varValue;
break;
}
}
}
</script>