How to fix this character encoding issue?

The send page is as follows:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script>
function send() {
    var chinese = document.getElementById('chinese').value;
    window.location = 'receive.html?' + chinese;
}
</script>
</head>
<body>
    <input id="chinese" type="text" name="chinese" value="" />
    <button onclick="send()">Submit</button>
</body>
</html>

The receive page is as follows:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script>
window.onload = function () {
    var chinese = location.search;
    document.getElementById('chinese').value = chinese;
}
</script>
</head>
<body>
    <input id="chinese" type="text" name="chinese" value="" />
</body>
</html>

The problem is that the receive page does not receive/display the Chinese characters correctly. For example, instead of 首页 it displays ?%E9%A6%96%E9%A1%B5, though it does display well in the query string in the browser address bar.


ANSWERS:


The value should be URI-encoded before you form the URL:

window.location = 'receive.html?' + encodeURIComponent(chinese);

Now that may not be all you have to do, because it's possible that the server could be causing problems, but you generally want to do that encoding anyway with input provided directly from an text field.



 MORE:


 ? SQL Syntax Error/Invalid Query - WAMP, phpMyAdmin
 ? how to write with a single byte character encoding?
 ? phpMyAdmin hiding syntax errors on bulk INSERT statements?
 ? How to fix wrong text file encoding?
 ? SQL syntax error generated by phpMyAdmin when updating field
 ? Which character encoding Python 3.x supports for file I/O?
 ? Which character encoding Python 3.x supports for file I/O?
 ? Which character encoding Python 3.x supports for file I/O?
 ? UnicodeEncodeError writing text with special character to file
 ? Why doesn't Python recognize my utf-8 encoded source file?