Results 1 to 8 of 8

Thread: script needed

  1. #1
    Join Date
    Apr 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow script needed

    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,

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <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", "&#241;", "ṭ", "ṇ", "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>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    The script fails horribly, in IE 6. Just passing on the information.
    - Mike

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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:
    Code:
      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:
    1. The user presses a key
    2. The function is fired
    3. The value is updated
    4. The user releases the key
    Thus, the function is operating on old data. What we want, and what onkeyup provides, is this:
    1. The user presses a key
    2. The value is updated
    3. The user releases the key
    4. The function is fired
    Thus, the function is operating on the new data.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •