Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

JavaScript Farsi TextBox

0.00/5 (No votes)
11 Jan 2006 1  
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