Search code examples
htmlcsshebrewbidi

How to handle right-to-left text-input fields the right way?


I am working on a multilingual layout. What worries me is:

How to handle text-input the right way?

I've build a JSFiddle to explain my problem.

  1. If I just add dir="rtl", the words appear from right to left, but not each character
  2. If I add the CSS style for right-to-left, the included numbers are also turned around

How can i combine numbers and text, so a hebrew input is showing correctly?


Solution

  • You can try this solution from here

    Example http://jsfiddle.net/0w5rydrL/1/

    The html

    <div class="text_direction" dir="rtl">
        <input type="text" onkeyup="rtl(this);" />
    </div>
    

    The javascript function

    function rtl(element){   
        if(element.setSelectionRange){
            element.setSelectionRange(0,0);
        }
    }