JS encodeURIComponent result different from the one created by FORM
Posted
by Marco Demaio
on Stack Overflow
See other posts from Stack Overflow
or by Marco Demaio
Published on 2010-04-09T13:47:46Z
Indexed on
2010/04/09
14:53 UTC
Read the original article
Hit count: 388
I thought values entered in forms are properly encoded by browsers.
But this simple test shows it's not true:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title></title>
</head><body>
<form id="test" action="test_get_vs_encodeuri.html" method="GET" onsubmit="alert(encodeURIComponent(this.one.value));">
<input name="one" type="text" value="Euro-€">
<input type="submit" value="SUBMIT">
</form>
</body></html>
When hitting submit button:
encodeURICompenent encodes input value into "Euro-%E2%82%AC"
while browser into the GET query writes only a simple "Euro-%80"
Could somone explain?
Or is encodeURIComponent doing unnecessary conversions?
© Stack Overflow or respective owner