Click here to Skip to main content
11,512,720 members (62,544 online)
Click here to Skip to main content

JavaScript Farsi TextBox

, 11 Jan 2006 63.6K 787 10
Rate this:
Please Sign up or sign in to vote.
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).

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=' !"#$%&#1548;&#1711;)(×+&#1608;-./0123456789:&#1603;,=.&#1567;@&#1616;&#1584;}&#1609;&#1615;&#1610;&#1604;&#1575;÷&#1600;&#1548;/&#8217;&#1583;×&#1563;&#1614;&#1569;&#1613;&#1601;&#8216;{&#1611;&#1618;&#1573;~&#1580;&#1688;&#1670;^_&#1662;&#1588;&#1584;&#1586;&#1610;&#1579;&#1576;&#1604;&#1575;&#1607;&#1578;&#1606;&#1605;&#1574;&#1583;&#1582;&#1581;&#1590;&#1602;&#1587;&#1601;&#1593;&#1585;&#1589;&#1591;&#1594;&#1592;<|>&#1617;'.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.

<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

Share

About the Author

Hamed J.I
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I began programming with C/C++ when i was 15. Then try to learn VC++ but at the middle of my reading .NET came.

I began to read C# and VB.NET and also began designing basic websites by FrontPage and developed some websites for our school and some other companis.

Later learn Microcontroller and design some digital circuits with PIC microcontrollers for a industrial controller company.

As I learned SQL and ASP.NET developed some website such as news portals that are active now.

Now i'm a software student and teach programming in computer institues. And have my own job by getting projects from companies.

Comments and Discussions

 
GeneralMy vote of 1 Pin
ali-rashidi3-Aug-13 7:35
memberali-rashidi3-Aug-13 7:35 
Generalasp.net javascript farsi textbox (IE,mozilla firefox,opera.....!!) [modified] Pin
amir movahedi2-Aug-09 7:52
memberamir movahedi2-Aug-09 7:52 
GeneralRe: asp.net javascript farsi textbox (IE,mozilla firefox,opera.....!!) Pin
Afflatus22-Mar-11 2:31
memberAfflatus22-Mar-11 2:31 
Generalit doesn't work in FireFox Pin
Member #307324718-Feb-07 19:37
memberMember #307324718-Feb-07 19:37 
Generalit doesn't work in FireFox Pin
Member #307324718-Feb-07 19:36
memberMember #307324718-Feb-07 19:36 
QuestionHow to change keys [modified] Pin
method0076-Aug-06 8:03
membermethod0076-Aug-06 8:03 
AnswerRe: How to change keys Pin
Active-y10-May-07 16:38
memberActive-y10-May-07 16:38 
GeneralRe: How to change keys Pin
method00710-May-07 16:50
membermethod00710-May-07 16:50 
Generalfarsi textbox Pin
ptvce15-May-06 0:20
memberptvce15-May-06 0:20 
GeneralRe: farsi textbox Pin
Hamed_ji21-May-06 3:09
memberHamed_ji21-May-06 3:09 
GeneralRe: farsi textbox Pin
ptvce21-May-06 19:40
memberptvce21-May-06 19:40 
GeneralRe: farsi textbox [modified] Pin
Hamed_ji22-May-06 2:17
memberHamed_ji22-May-06 2:17 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150604.1 | Last Updated 11 Jan 2006
Article Copyright 2006 by Hamed J.I
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid