Encoding GBK2312 Condundrum
- by user792271
I am an amateur coder and I have a small problem.
My goal is to have one text input with two buttons.
The first button uses a bit of
Javascript called SundayMorning to
translate the text (to Chinese)
The second button submits the text to a
URL. The URl requires that Chinese
text be encoded it in GBK2312
character set.
I have duct taped together various found code to the result I have now. Due to the finicky behavior of the SundayMorning Javascript, my solution is to have two input boxes, the second of which I will hide.
Right now, this doesn't work:
I am unable to encode the Chinese in GBK2312, no matter what I try.
BONUS CONUNDRUM: The second box copies my input letter by letter as I type, but does not copy the Chinese translation that the Javascript returns.
Sorry for my janky amateur code. I defer to those more clever, if you have any kind suggestions.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<script type='text/javascript' Src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js'>
</script>
///THIS JS TRANSLATES THE TEXT INLINE
<script
type="text/javascript"
src="jquery.sundaymorning.js">
</script>
<script type="text/javascript">
$(function() {
$('#example3').sundayMorningReset();
$('#example3 input[type=image]').click(function(evt) {
$.sundayMorning(
$('#example3 input[type=text]').val(),{source:'en', destination:'ZH', menuLeft:evt.pageX, menuTop:evt.pageY},function(response) {$('#example3 input[type=text]').val(response.translation);});});});
</script>
///
///THIS PUTS THE CONTENT OF THE TRANSLATION BOX INTO THE SUBMISSION BOX
<script type="text/javascript">
$(document).ready(function(){
var $url = $("#url");
$("#track").keyup(function() {
$url.val(this.value);});
$("#track").blur(function() {
$url.val(this.value);});});
</script>
///THIS PUTS THE CONTENT OF THE SUBMISSION INSIDE A URL
<SCRIPT type="text/javascript">
function goToPage(url)
{
var initial = "http://example.com/";
var extension = ".html";
document.something.action=initial+url+extension;
}
</SCRIPT>
</head>
<body>
<div id="featured">
<div id="example3">
<input type="text" name="track" id="track" value="" class="box"onkeydown="javascript:if (event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('mama').click();}};"/>
<input type="image" src="http://taobaofieldguide.com/images/orange-translate-button.png" id="searchsubmit" value="Translate" class="btn" />
</div>
<FORM name="something" method="post" onsubmit="goToPage(this.url.value);">
<input type="text" id="url";>
<INPUT type="submit" id="mama" value="GO" >
</FORM>
</div>
</body>