P2000 said:
Thanks!
What about something more general?
Sorry for not making it clear in the first place, but my goal is to
create something to convert between different keyboard in different
languages (for people how need to use their native keyboard from a
different place).
So... how can I change it without the uppercase, say like that:
a->X
b->Y
c->Z
do I do it with an array of some sort?
Thanks again,
Sam
You'll find the regulars here to be very much against top-posting
I think you're going to have to pull the functionality out of the
onkeyup attribute and put it in its own function:
<script type="text/javascript">
var letterMappings = {
'a': 'X',
'b': 'Y',
'c': 'Z'
};
function getMapping(char)
{
return letterMappings[char] || char;
}
function remapInput(element, target)
{
document.getElementById('output').value =
element.value.replace(/./g, getMapping);
}
</script>
....
<input name="source" type="text" onkeyup="remapInput(this);" />
<input id="output" type="text" />
Even better would be to remove the contents of that <script> to a
separate .js file - particularly for XHTML, failure to remove or escape
(the latter of which destroys readability of the code) javascript to a
separate file causes validation errors.
In the function remapInput, the regex
/./
matches any single character. The character is then passed to
getMapping, which returns either the mapped character (as defined in the
letterMappings object), or, if no mapping is defined, the original
character.
Jeremy