"Grant Wagner" <gw*****@agricoreunited.com> wrote in message news:41***************@agricoreunited.com...
| Newbie wrote:
|
| > How would I modify this form
| > to encode *all* the characters
| > in the 'source' textarea to the
| > '%xx' format & place result
| > code into the 'output' textarea?
| > (cross browser compatable)
| >
| > Any help is appreciated.
| >
| > Regards.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Encode And Decode Entire Text or Html to '%xx' format
</title>
</head>
<body>
<script type="text/javascript">
<!--
function encode(f) {
var ta = f.elements['source'].value;
var hex;
var s = [];
for (var i = 0; i < ta.length; i++) {
hex = (ta.charCodeAt(i) % 256).toString(16);
s.push((hex.length < 2 ? '0' : '') + hex);
}
f.elements['output'].value = '%' + (s.join('%')).toUpperCase();
}
function decode(f) {
var ta = f.elements['source'].value.split(/%/);
var s = [];
for (var i = 0; i < ta.length; i++) {
s.push(String.fromCharCode(parseInt(ta[i], 16)));
}
f.elements['output'].value = s.join('');
}
//-->
</script>
Text and Html "%xx" Converter<br>
<form name="form1" method="post" action="">
Original Text:<br>
<textarea name="source" cols="79" rows="8" wrap="VIRTUAL">Original Text or Html code
to have the *entirety* of
the characters converted
to '%xx' formated codes.
</textarea>
<br>
<br>
<br>
Output Text<br>
<textarea name="output" cols="79" rows="8" wrap="VIRTUAL"></textarea>
<br>
<input type="button" name="Encode" value="Encode" onclick="encode(this.form);">
<input type="button" name="Decode" value="Decode" onclick="decode(this.form);">
<input type="reset" name="Reset" value="Reset">
</form>
</body>
</html>
| I hope I get a good mark from your teacher.
|
| --
| Grant Wagner <gw*****@agricoreunited.com>
| comp.lang.javascript FAQ -
http://jibbering.com/faq
I'm teaching myself & my teacher was really impressed :-)
Thanks.
PS:
Will this work with 3.xx and 4.xx old JS enabled browsers too?