I am trying to learn some jQuery and I am setting up a test page with the following code:
<a id='encode' href='javascript: void(0)'>encode</a> |
<a id='decode' href='javascript: void(0)'>decode</a> |
<br/>
<textarea id='randomString' cols='100' rows='5'></textarea>
<script type='text/javascript'>
$(document.ready(function () {
$('#encode').click(function() {
$('#randomString').val(escape($('#randomString').val()));
});
$('#decode').click(function() {
$('#randomString').val(unescape($('#randomString').val()));
});
});
</script>
The idea is that I can put something in the text box and click either “encode” or “decode”, and it will either run away or undo what I placed in the text box.
This code works fine, but my question is related to how I change the value of the text area. In my code, I select the textarea value twice: once (un) escapes from it, and once again to change the value. IMO this seems awkward and possibly unnecessary. I was thinking, maybe I could do something like this:
$('#randomString').val(escape(this));
this, , , , #randomString, , $('#randomString')?