Click here to Skip to main content
15,892,199 members
Articles / Programming Languages / Javascript
Article

JavaScript Farsi TextBox

Rate me:
Please Sign up or sign in to vote.
2.96/5 (13 votes)
11 Jan 2006 81.3K   1.1K   10   12
A TextBox for write Farsi

Introduction

On the internet some times we need get information from user in language other than English. for example we want the user type his name in Perisan language. there is two way to do this. First you can hope the user installed the farsi language in computer and change the language of windows to type.

This way have one Big problem and that is the Farsi Language that diffrent windows have is diffrent i mean. for Example the character codes in diffrent windows is diffrent.

The second way to handle both problems is using some javascript codes. in this way the user don't need to have Farsi Installed on machine. When the user type the code that user type convert to Farsi Language Unicode and write in the text box.

How do it ?

We must declare a function to convert typed character to Unicode.(Your page language must set to UTF-8).

JavaScript
function keyenter(field,e)
{
var key;
if (window.event)
   key = window.event.keyCode;
if (key>31)
  if (key<128)
  {
    if (window.event)
      window.event.keyCode=' !"#$%،گ)(×+و-./0123456789:ك,=.؟@ِذ}ىُيلا÷ـ،/’د×؛َءٍف‘{ًْإ~جژچ^_پشذزيثبلاهتنمئدخحضقسفعرصطغظ<|>ّ'.charCodeAt(key-32);
  }
}
Note: Remember that the characters must not convert to unicode numbers and must look likes what you see here.

In the definition of textbox you must call OnKeyPress event to the function you have declared.

HTML
<input onkeypress="keyenter(this,event)" type="text" name="T1" size="20">

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
ali-rashidi3-Aug-13 7:35
ali-rashidi3-Aug-13 7:35 
Generalasp.net javascript farsi textbox (IE,mozilla firefox,opera.....!!) [modified] Pin
amir movahedi2-Aug-09 7:52
amir movahedi2-Aug-09 7:52 
GeneralRe: asp.net javascript farsi textbox (IE,mozilla firefox,opera.....!!) Pin
Afflatus22-Mar-11 2:31
Afflatus22-Mar-11 2:31 
Generalit doesn't work in FireFox Pin
barbod_blue18-Feb-07 19:37
barbod_blue18-Feb-07 19:37 
Generalit doesn't work in FireFox Pin
barbod_blue18-Feb-07 19:36
barbod_blue18-Feb-07 19:36 
QuestionHow to change keys [modified] Pin
method0076-Aug-06 8:03
method0076-Aug-06 8:03 
Hi . could u tell me how to change the order of keys. I want to make it like the keyboar layout shown below.

In another word how to change the keys in the folloing line:

window.event.keyCode=' !"#$%،گ)(×+و-./0123456789:ك,=.؟@ِذ}ىُيلا÷ـ،/’د×؛َءٍف‘{ًْإ~جژچ^_پشذزيثبلاهتنمئدخحضقسفعرصطغظ<|>ّ'.charCodeAt(key-32);

so if we press letter "s" pressed on keyboard it output "س" and similerly for the rest of keys as shown in pic. this way we can type so fast without learing farsi touch typing. I be happy if u help me achive this task.Thanks


picture:
[URL=http://www.theimagehosting.com][IMG]http://images6.theimagehosting.com/board.10f.JPG[/IMG][/URL]



-- modified at 14:04 Sunday 6th August, 2006
AnswerRe: How to change keys Pin
Active-y10-May-07 16:38
Active-y10-May-07 16:38 
GeneralRe: How to change keys Pin
method00710-May-07 16:50
method00710-May-07 16:50 
Generalfarsi textbox Pin
ptvce15-May-06 0:20
ptvce15-May-06 0:20 
GeneralRe: farsi textbox Pin
Hamed J.I21-May-06 3:09
Hamed J.I21-May-06 3:09 
GeneralRe: farsi textbox Pin
ptvce21-May-06 19:40
ptvce21-May-06 19:40 
GeneralRe: farsi textbox [modified] Pin
Hamed J.I22-May-06 2:17
Hamed J.I22-May-06 2:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.