+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15

Thread: Change TextBox input language

  1. #1
    Off-Topic Trolless dragon rider is an unknown quantity at this point dragon rider's Avatar
    Join Date
    Jul 2008
    Posts
    119
    Rep Power
    4

    Change TextBox input language

    again

    Another one that I've been searching for a while..
    how can i change a textbox input language from english to greek?
    What I mean... In my keyboard I have 2 languages, english and greek. I want, when I type to a textbox, to write in greek, even if the language selected is english.
    Thank you

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    The only thing I can think of is to use the JavaScript replace during the onkeyup event and replace the corresponding character with the appropriate Greek character. You could create an array and then read from that array.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Off-Topic Trolless dragon rider is an unknown quantity at this point dragon rider's Avatar
    Join Date
    Jul 2008
    Posts
    119
    Rep Power
    4

    Quote Originally Posted by jmurrayhead View Post
    The only thing I can think of is to use the JavaScript replace during the onkeyup event and replace the corresponding character with the appropriate Greek character. You could create an array and then read from that array.
    how can I replace it while typing?

    I mean, while typing the english characters to be replaced by the greek ones..

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    I think the onKeyUp event will work best for this. See here: JavaScript onkeyup Event

    You could have an array that holds English characters and Greek characters. Then in the onKeyUp event, find the index of the corresponding English character and use that to find the corresponding Greek character. Then use the JavaScript replace function to replace it: Javascript Tutorial - Replace

    Hope this helps
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Off-Topic Trolless dragon rider is an unknown quantity at this point dragon rider's Avatar
    Join Date
    Jul 2008
    Posts
    119
    Rep Power
    4

    I'll try it and I'll let you know.. Thank you..

  6. #6
    Off-Topic Trolless dragon rider is an unknown quantity at this point dragon rider's Avatar
    Join Date
    Jul 2008
    Posts
    119
    Rep Power
    4

    Why this doesn't work?
    Code:
    <%
    function ChkStr(strT)
    	strT = Replace(strT, "a", "α")
    	strT = Replace(strT, "b", "β")
    	ChkStr = strT
    End Function
    %>
    
    <input type="text"
    id="test" onKeyUp="ChkStr(this.id)">
    

  7. #7
    Off-Topic Trolless dragon rider is an unknown quantity at this point dragon rider's Avatar
    Join Date
    Jul 2008
    Posts
    119
    Rep Power
    4

    Found it!

    Code:
    function greeklish(x)
    {
    var y=document.getElementById(x).value;
    y=y.replace("a", "α");
    y=y.replace("b", "β");
    y=y.replace("g", "γ");
    document.getElementById(x).value=y
    }
    
    
    <input type="text"
    id="greek" onKeyUp="greeklish(this.id)">
    
    I haven't add all the letters yet but it's OK, right?

  8. #8
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I was just about to post this to see if it's any good
    Code:
    function change_letter(id){
      var txt = document.getElementById(id).value;
      var old_txt = '';
      var new_txt = '';
         for(var i=txt.length-1;i<txt.length;i++){
             old_txt = txt.charCodeAt(i);
             //chr ref for a=97 for z=123 isNaN takes care of any other key presses
                if(old_txt>=97&&old_txt<=123&&!isNaN(old_txt)){
                   //difference in chr numbers between a and alpha is 848
                   new_txt = String.fromCharCode(txt.charCodeAt(i)+848);
                   //replace the old character for the new one
                   document.getElementById(id).value = txt.replace(String.fromCharCode(old_txt), new_txt);
                }
         }
    }
     

    To use it:-
    Code:
    <input type="text" id="textbox1" onkeyup="change_letter(this.id)" /> 

    I found the difference between the chr values of a and alpha to be 848. So it grabs the last letter from the textbox checks the value is between a and z and then adds 848 to the chr value. Then it replaces the old character with the new one. I thought this would save having to add all the letters manually.

    The only slight problem with this method is where characters do not have direct replacements. Maybe you could add something in to filter these.

    Hope that helps.

  9. #9
    Off-Topic Trolless dragon rider is an unknown quantity at this point dragon rider's Avatar
    Join Date
    Jul 2008
    Posts
    119
    Rep Power
    4

    Quote Originally Posted by richyrich View Post
    The only slight problem with this method is where characters do not have direct replacements. Maybe you could add something in to filter these.
    RR

    For the english characters that don't exist in greek I did this:
    Code:
    if (y.match("c")) 
    {
    alert("Μόνο ελληνικά");
    y=y.replace("c", "");
    }
    

    The problem though is that with your code starts ok (a=α, b=β, ...) but then it replaces your "m" with our "n", your "k" with our "l" and other... it's not correct..

  10. #10
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Yeah...I thought that might be a problem...

    What you need to do is, if c isn't a letter in greek, any letters after c have to only have 847 added to them.

    Then if, for example if j isn't a letter in greek, anything after j would only have 846 added to it.

    Depending on how many letters don't have a replacement, perhaps a switch statement might be better.

    Hope that makes sense...

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. textbox validation
    By todd2006 in forum JavaScript Programming
    Replies: 6
    Last Post: July 2nd, 2008, 02:30 PM
  2. find words and change
    By todd2006 in forum JavaScript Programming
    Replies: 4
    Last Post: July 2nd, 2008, 10:58 AM
  3. Change to Reputation System
    By jmurrayhead in forum Announcements
    Replies: 0
    Last Post: June 2nd, 2008, 10:57 PM
  4. Textbox or List help
    By Rebelle in forum JavaScript Programming
    Replies: 9
    Last Post: April 21st, 2008, 11:00 AM

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

SEO by vBSEO