View Full Version : script needed
sweetboy
04-07-2007, 05:59 AM
hi all we are developing tamil website.for that we use phonetic key board layout in tamil.it works fine but we need to display the combinations of letters(that is if they type 'k' it displays all the combination for the letter 'k','k','ka','ku','kaa' etc) that makes our site user friendly.
That means if the user type the letter 'k', the script should display the all combinations of the letter 'k'. Please reply soon.
:) thanks,:confused:
djr33
04-07-2007, 07:33 AM
Shouldn't this be system-based, not on the site? I'm not quite sure what you are going for.
Seems quite complex to me.
<script type="text/javascript">
Array.prototype.combine = function(arr) {
if(arguments.length > 1 || !(arr instanceof Array))
arr = Array.prototype.slice.apply(arguments);
for(var i = 0, r = []; i < this.length; ++i)
for(var j = 0, e = this[i]; j < arr.length; ++j)
r.push(this[i] + arr[j]);
return r;
};
var vowels = ["a", "ā", "i", "ī", "u", "ū", "e", "ē", "ai", "o", "ō", "au"],
consonants = [
"k", "ṅ", "c", "ñ", "ṭ", "ṇ", "t", "n", "p",
"m", "y", "r", "l", "v", "ẓ", "ḻ", "ṛ", "ḷ", "ṟ", "R", "ṉ", "N",
"j", "ṣ", "s", "h", "kṣ"
];
</script>
<form action="" onsubmit="return false;">
<input type="text" style="width: 2em;" onkeyup="
this.form.elements['uyirmei'].value =
(consonants.indexOf(this.value) > -1) ?
[this.value].combine(vowels).join(' ') :
'';
">
<textarea name="uyirmei"></textarea>
</form>
mburt
04-07-2007, 02:13 PM
The script fails horribly, in IE 6. Just passing on the information.
djr33
04-07-2007, 02:18 PM
I still don't understand the original question, so I wouldn't know if that scripts fits it. Looks cool, though. Haven't tested it.
One thing I notice is that "onkeyup" might not be the best. Using onkeydown ensures that it registers each keystroke. You can, though it is unlikely, type without releasing a key.
Press "a" and hold, then quickly press another letter.
Works for me.
You're right, I was relying on Array.prototype.indexOf(), which doesn't exist in anything but Spidermonkey. Add the following code to the top of the script to make it work:
if(typeof Array.prototype.indexOf === "undefined")
Array.prototype.indexOf = function(v) {
for(var i = 0; i < this.length; ++i)
if(this[i] == v)
return i;
return -1;
};Thanks mburt!
One thing I notice is that "onkeyup" might not be the best. Using onkeydown ensures that it registers each keystroke. You can, though it is unlikely, type without releasing a key.Which is exactly why we use onkeyup... if onkeydown were used, the sequence of events would be something like this:The user presses a key The function is fired The value is updated The user releases the keyThus, the function is operating on old data. What we want, and what onkeyup provides, is this:The user presses a key The value is updated The user releases the key The function is firedThus, the function is operating on the new data.
djr33
04-07-2007, 10:43 PM
I wasn't aware that onkeydown wouldn't immediately have the effect of changing the value in the field.
However, I'm just pointing out that there are ways to type that would confuse such a system and end up with odd results, tough it is likely not a major issue.
Of course there are. Personally, I'd recommend against such a system entirely: I don't believe language should be censored at all, and I don't believe it's possible to do so effectively with a machine.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.