Question

So I have a page, and try to submit a form along with user-entered data.

Demo: http://jsfiddle.net/DerekL/Cck8Q/

However, the browser sends out the data in UTF-8, while the server requires it to be in Big5. Basically this means,

encodeURIComponent("電")    //"%E9%9B%BB"

this is not using the correct character set, and the correct string should be

%B9q

Is there anyway to "make" the browser to send the data using Big5? JavaScript conversion indeed is possible, but it would end up like this.

Was it helpful?

Solution

If you're only looking for encoding in HTML form submission, not JS encoding conversion, you can take advantage of the accept attribute (HTML4) and/or accept-charset attribute (HTML5) of <form>:

<form action="..." method="get" accept="BIG5" accept-charset="BIG5">

Online demo (Checked on a Chrome on XP Simplified Chinese version).

MDN document about <form> attributes

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