Reputation: 1195
If you try encodeuricomponent by default it works. What I'm trying to do is to change the href of an anchor tag whenever text is entered into an input field.
My code:
<!DOCTYPE html>
<html>
<body>
<p>Click the button to encode a URI.</p>
<input type="text" oninput="myFunction()">Try it</button>
<a id="demo" href="#">Test</a>
<script>
function myFunction() {
document.getElementById("demo").href = encodeURIComponent("005 139 024 6772");
}
</script>
</body>
</html>
So when you enter text, what should happen, is the href should change to an encoded version of what you typed in, instead, what happens is you get an identical match to what you typed in.
Why?
Upvotes: 1
Views: 885