Question

Im trying to decode the %20 in the URL link so that i cant get my value without adding %20 in the textfield when i decode the code from current page to next page, below is my coding for decode the %20 and where i place

function loadRecord(i){
    var item=dataset.item(i);
    fname.value = item['fname'];
    id.value = item['id'];
    window.location.href = decodeURIComponent("userup2.html?id="+item['id']+"&fname="+item['fname']+"&val=300");
    return false;
}

This is the current and will redirect to second page to display the data

enter image description here

enter image description here

why it still display the %20 even though i code the decodeURIComponent? please help

Was it helpful?

Solution

You have to decode the URI when it's passed to your input. Decoding it to pass it to window.location is correct, but the browser will escape it again.

I assume you take the input value from the params. So where you set the input value from the params (in your case, certainly in the document userup2.html, you have to decode the URI.

So where you set the input value from the params, you have to decode it again:

document.getElementByTagName('input').value = decodeURI(...your code to get the params);

OTHER TIPS

why it still display the %20 even though i code the decodeURIComponent?

Browser is encoding the url to make it a valid URL. Even though you are decoding it, its again assigned to window.location.href, so the control is back to browser.

You cannot bypass it. Instead decode the url at the receiving end.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top