Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Sponsored Links

Discuss "Change TextBox input language" in the JavaScript Programming forum.

JavaScript Programming - Javascript is a cross-browser client-side scripting language. Discuss Javascript and AJAX related scripts here.


Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old July 2nd, 2008, 03:57 PM
Barn Newbie
 
Join Date: Jul 2008
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
dragon rider is an unknown quantity at this point
Default 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
Reply With Quote
Sponsored Links
  #2  
Old July 2nd, 2008, 04:59 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 946
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

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 with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding

Reply With Quote
  #3  
Old July 2nd, 2008, 05:02 PM
Barn Newbie
 
Join Date: Jul 2008
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
dragon rider is an unknown quantity at this point
Default

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..
Reply With Quote
  #4  
Old July 2nd, 2008, 05:07 PM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 946
Thanks: 22
Thanked 93 Times in 90 Posts
Blog Entries: 6
Rep Power: 4
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

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
Reply With Quote
  #5  
Old July 2nd, 2008, 05:09 PM
Barn Newbie
 
Join Date: Jul 2008
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
dragon rider is an unknown quantity at this point
Default

I'll try it and I'll let you know.. Thank you..
Reply With Quote
  #6  
Old July 4th, 2008, 04:35 AM
Barn Newbie
 
Join Date: Jul 2008
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
dragon rider is an unknown quantity at this point
Default

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)">
Reply With Quote
  #7  
Old July 4th, 2008, 05:45 AM
Barn Newbie
 
Join Date: Jul 2008
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
dragon rider is an unknown quantity at this point
Default

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?
Reply With Quote
  #8  
Old July 4th, 2008, 06:19 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 456
Thanks: 31
Thanked 42 Times in 42 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

Default

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.
Reply With Quote
  #9  
Old July 4th, 2008, 07:50 AM
Barn Newbie
 
Join Date: Jul 2008
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 1
dragon rider is an unknown quantity at this point
Default

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..
Reply With Quote
  #10  
Old July 4th, 2008, 08:09 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 456
Thanks: 31
Thanked 42 Times in 42 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

Default

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 With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > JavaScript Programming

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
textbox validation todd2006 JavaScript Programming 6 July 2nd, 2008 01:30 PM
find words and change todd2006 JavaScript Programming 4 July 2nd, 2008 09:58 AM
Change to Reputation System jmurrayhead Announcements 0 June 2nd, 2008 09:57 PM
Textbox or List help Rebelle JavaScript Programming 9 April 21st, 2008 10:00 AM


All times are GMT -4. The time now is 08:47 AM.



Content Relevant URLs by vBSEO 3.2.0