How to Auto detect input writing position in JQuery

View: 428    Dowload: 0   Comment: 0   Post by: hanhga   Category: HTML-CSS template   Fields: Other

When we write right to left  language characters in textarea the direction of the writing will automatically be changed from right to left and vice versa

Example: JQuery .

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><script>
$(document).ready(function() {
 $("#txt_post_contents").on("mousemove mouseleave keyup", function () {
 var post_contents = $.trim(document.getElementById("txt_post_contents").value);
  
 if(post_contents.length == 1||post_contents.length == 2){
 var langType = new RegExp("[\x00-\x80]+");
 var AsciiPostContents = langType.test(post_contents);
  
 if(AsciiPostContents){
 $("#txt_post_contents").css('direction','ltr');
 }
 else{
 $("#txt_post_contents").css('direction','rtl');
 $("#txt_post_contents").css('font-size','16px');
 }
 } 
 });
});
</script>

Example: Html.

<textarea id="txt_post_contents" name="txt_post_contents" rows="3"></textarea>

How to Auto detect input writing position in JQuery

When we write right to left language characters in textarea the direction of the writing will automatically be changed from right to left and vice versa

Posted on 31-08-2016 

Comment:

To comment you must be logged in members.

Files with category

 
File suggestion for you
File top downloads
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd