By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,441 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

text direction right to left for arabic text input

P: 52
Dear Sir,
Is there any way or property for chaning the text diriction from right to left automatically when i want to take arabic text as a input . now this possible by ALT+SHIFT pressing . but i want to do it automatically by using javscript or style sheet .
Please try to reply to me.

Regards,
Faruk Chowdhury
May 22 '08 #1
Share this Question
Share on Google+
21 Replies


hsriat
Expert 100+
P: 1,654
Dear Sir,
Is there any way or property for chaning the text diriction from right to left automatically when i want to take arabic text as a input . now this possible by ALT+SHIFT pressing . but i want to do it automatically by using javscript or style sheet .
Please try to reply to me.

Regards,
Faruk Chowdhury
See the text direction property if its of any use.

If not then you may have a look at dir and lang attribute of textarea tag.

Place a language selector radio button and call the function to change the properties onclick event of the radio button.

PS. Ask such questions in JavaScript forum.
May 22 '08 #2

Atli
Expert 5K+
P: 5,058
I have moved this thread over to the Javascript Forums.
Please try to post you questions in the appropriate forums.

Thanks.
May 22 '08 #3

P: 52
Dear Sir,
When I press Alt+Shift in a text control, the cursor turns Right-To-Left.
I want it without pressing Alt+Shift, I want to when I click a text control
the cursor automatically turn to Right-To-Left.
please try to reply.

Thanks in advance.

Regards,
Faruk Chowdhury
May 22 '08 #4

P: 52
Dear Sir,
Thank you for your quick reply.
When I press Alt+Shift in a text control, the cursor turns Right-To-Left.
I want it without pressing Alt+Shift, I want to when I click a text control
the cursor automatically turn to Right-To-Left.

i sent this question to javascript forum also.

According to your previous reply the direction goes from left to right but i need as when I click a text control the cursor automatically turn to Right-To-Left.

so if you can please help me.

thanks in advance.

Regards,
Faruk Chowdhury


See the text direction property if its of any use.

If not then you may have a look at dir and lang attribute of textarea tag.

Place a language selector radio button and call the function to change the properties onclick event of the radio button.

PS. Ask such questions in JavaScript forum.
May 22 '08 #5

hsriat
Expert 100+
P: 1,654
According to your previous reply the direction goes from left to right but i need as when I click a text control the cursor automatically turn to Right-To-Left.

so if you can please help me.

thanks in advance.

Regards,
Faruk Chowdhury
Expand|Select|Wrap|Line Numbers
  1. function urduWriter(onOrOff) {
  2.     document.getElementById('ta').style.direction =onOrOff ? 'rtl' : 'ltr';
  3.     //document.getElementById('ta').dir = onOrOff ? 'rtl' : 'ltr'; 
  4. }
Call this function to change the direction from right to left as urduWriter(true).
To restore the direction, call urduWriter(false)
May 22 '08 #6

acoder
Expert Mod 15k+
P: 16,027
Merged threads. Thread had already been moved to this forum.

Moderator.
May 23 '08 #7

Plater
Expert 5K+
P: 7,872
I am really unsure why this link did not solve the problem:
http://www.w3schools.com/htmldom/pro..._direction.asp
May 23 '08 #8

hsriat
Expert 100+
P: 1,654
I am really unsure why this link did not solve the problem:
http://www.w3schools.com/htmldom/pro..._direction.asp
I guess he's not aware of how to change this property with JavaScript.
Or perhaps the w3school's server was down when he clicked this link.

But its working, I just tested...
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">function urduWriter(onOrOff) {
  2.     document.getElementById('ta').style.direction =onOrOff ? 'rtl' : 'ltr';
  3. }
  4. </script>
  5. <textarea id="ta"></textarea><br>
  6. <button onclick="urduWriter(true);">On</button>
  7. <button onclick="urduWriter(false);">Off</button>
May 23 '08 #9

Plater
Expert 5K+
P: 7,872
I guess he's not aware of how to change this property with JavaScript.
Or perhaps the w3school's server was down when he clicked this link.
Why not just build your html pages with it set already? The OP said js/CSS but it might have been because they were unaware that it can be done with a regular html attribute.
May 23 '08 #10

hsriat
Expert 100+
P: 1,654
Why not just build your html pages with it set already? The OP said js/CSS but it might have been because they were unaware that it can be done with a regular html attribute.
good point...
but I have seen such pages.. they show radio button by which you can select the language you want to type in... I just guessed it might be similar caase...

so this will work ...[html]<textarea dir="rtl"></textarea>[/html]
May 23 '08 #11

Plater
Expert 5K+
P: 7,872
There are a number things I have discovered here. Text direction seems to automatically inherit from it's parent object:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>Direction Test</title>
  4.         <script type="text/javascript">
  5.             function changeTextDirection()
  6.             {
  7.                 var curdir=document.getElementById("mybody").style.direction;
  8.                 if(curdir=="ltr")
  9.                 {
  10.                     document.getElementById("mybody").style.direction="rtl";
  11.                 }
  12.                 else
  13.                 {
  14.                     document.getElementById("mybody").style.direction="ltr";
  15.                 }
  16.             }
  17.         </script>
  18.  
  19.     </head>
  20.     <body id="mybody" dir="rtl">
  21.         <span >fred jones</span><br/>
  22.         <div > bibbidy bop</div><br/>
  23.         <input type="text" value="some text" /><br/>
  24.         <textarea >This is some text</textarea><br/>
  25.         <input type="button" dir="inherit" onclick="changeTextDirection();" value="Swap It"/>
  26.     </body>
  27. </html>
  28.  
There is also a css property:
Expand|Select|Wrap|Line Numbers
  1. p { 
  2.   direction:ltr; 
  3.  
http://www.1keydata.com/css-tutorial/text.php#direction


So if you only want the inputboxes/textareas to switch, you can apply a special CSS tag to them and have them all start out with the right-to-left set.
May 23 '08 #12

P: 52
Dear Sir,
Thank you for cooperation.
my problem is with the use of ALT+SHIFT in the input box to write arabic text. i want to do this automatically i.e when i click in the input box the ALT+ SHIFT task will be done by programatically .
According to your code the directiong is changing from left to right but still i have to use the ALT+SHIFT key for taking the arabic input.

So if you have any idea please write to me.

Thanks in advance .

Regards,
Faruk Chowdhury



There are a number things I have discovered here. Text direction seems to automatically inherit from it's parent object:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <title>Direction Test</title>
  4.         <script type="text/javascript">
  5.             function changeTextDirection()
  6.             {
  7.                 var curdir=document.getElementById("mybody").style.direction;
  8.                 if(curdir=="ltr")
  9.                 {
  10.                     document.getElementById("mybody").style.direction="rtl";
  11.                 }
  12.                 else
  13.                 {
  14.                     document.getElementById("mybody").style.direction="ltr";
  15.                 }
  16.             }
  17.         </script>
  18.  
  19.     </head>
  20.     <body id="mybody" dir="rtl">
  21.         <span >fred jones</span><br/>
  22.         <div > bibbidy bop</div><br/>
  23.         <input type="text" value="some text" /><br/>
  24.         <textarea >This is some text</textarea><br/>
  25.         <input type="button" dir="inherit" onclick="changeTextDirection();" value="Swap It"/>
  26.     </body>
  27. </html>
  28.  
There is also a css property:
Expand|Select|Wrap|Line Numbers
  1. p { 
  2.   direction:ltr; 
  3.  
http://www.1keydata.com/css-tutorial/text.php#direction


So if you only want the inputboxes/textareas to switch, you can apply a special CSS tag to them and have them all start out with the right-to-left set.
May 23 '08 #13

Plater
Expert 5K+
P: 7,872
Ok, well alt+shift does nothing for me, so it must be some special language support feature on your system.
It does not have anything to do with the text direction it would seem so that was a red herring.

I am not sure how you would change the system local of a client machine through a webpage, maybe somebody else can help?
May 23 '08 #14

hsriat
Expert 100+
P: 1,654
Dear Sir,
Thank you for cooperation.
my problem is with the use of ALT+SHIFT in the input box to write arabic text. i want to do this automatically i.e when i click in the input box the ALT+ SHIFT task will be done by programatically .
According to your code the directiong is changing from left to right but still i have to use the ALT+SHIFT key for taking the arabic input.

So if you have any idea please write to me.

Thanks in advance .

Regards,
Faruk Chowdhury
Did you try the post # 9?
May 23 '08 #15

Tarantulus
100+
P: 114
I think everybody is missing the point here, the gent is trying to get his CURSOR to move "in reverse" so he can type input the arabic way...

unfortunately, I think this is impossible...

the alt+shift thing is a windows language setup, and thus cannot be controlled from a browser window.

EDIT: ActiveX perhaps, but thats IE specific, and VERY dodgy....
May 23 '08 #16

Plater
Expert 5K+
P: 7,872
Reverse? When text goes right to left, so does the cursor right?
In RTL mode if i press c u r s e r I see in my textbox ressuc| where the | is my cursor. Everything is lined up to the right hand side. Opposite of left to right writing.
May 23 '08 #17

hsriat
Expert 100+
P: 1,654
Reverse? When text goes right to left, so does the cursor right?
In RTL mode if i press c u r s e r I see in my textbox ressuc| where the | is my cursor. Everything is lined up to the right hand side. Opposite of left to right writing.
No, actually the Arabic languages are written from right to left like this
...E...D...C...B...A
<-- <-- <--

(of course they don't call it ABCD..)

So what he (OP) exactly wants is.
1. Text should be right aligned
2. When a letter is typed, the cursor should come in the left of the recently typed letter, instead of right side of the letter.

Just assume it like you are looking at the monitor through a mirror while typing English in the textarea.

The solutions dir and style.direction just fulfills the first need listed above, but not the second one.

So for the second one, you would need to find the position of the cursor (caret position). And using focus(caret), move the cursor to caretPosition-1 position every time you type in something (onkeypress). This won't be very easy though.

PS: Google for "Urdu editor JavaScript", you may find something useful.
May 23 '08 #18

P: 52
Dear Sir,
Thanks to all.
can you tell me how to execute key sequenec combinition using javascript i.e when i will click a buttton it will execute the key code for ALT and SHIFT key ?
please try to write to me.

Regards,
Faruk Chowdhury

No, actually the Arabic languages are written from right to left like this
...E...D...C...B...A
<-- <-- <--

(of course they don't call it ABCD..)

So what he (OP) exactly wants is.
1. Text should be right aligned
2. When a letter is typed, the cursor should come in the left of the recently typed letter, instead of right side of the letter.

Just assume it like you are looking at the monitor through a mirror while typing English in the textarea.

The solutions dir and style.direction just fulfills the first need listed above, but not the second one.

So for the second one, you would need to find the position of the cursor (caret position). And using focus(caret), move the cursor to caretPosition-1 position every time you type in something (onkeypress). This won't be very easy though.

PS: Google for "Urdu editor JavaScript", you may find something useful.
May 25 '08 #19

hsriat
Expert 100+
P: 1,654
Dear Sir,
Thanks to all.
can you tell me how to execute key sequenec combinition using javascript i.e when i will click a buttton it will execute the key code for ALT and SHIFT key ?
please try to write to me.

Regards,
Faruk Chowdhury
Believe me, that's not going to work. ALT SHIFT is just a language setting on your machine but not general.

And you are not even telling what is the problem with the solutions we provided. How long can we keep on doing guess work?
May 25 '08 #20

P: 52
Dear Sir,
According the previous solutions it just changes the direction from left to right .
i think for my prblem i need to know how to execute key code sequence by javascript.
please if you can try to reply to me.

Thanks in advance .

Regards,
Faruk Chowdhury.
May 26 '08 #21

acoder
Expert Mod 15k+
P: 16,027
You could try manually firing events, though I don't know if it would work. Have a read.
May 27 '08 #22

Post your reply

Sign in to post your reply or Sign up for a free account.