I have a textarea
which can take both English and Arabic language.
The English language starts from left to right. So, the cursor should begin in the left.
The Arabic language starts from the right. So the cursor should begin in the right.
How can I change the position of the cursor when the user changes his language? If his language is English the cursor should be on the left and vice-versa.
The user can change his language using ALT + SHIFT
in the keyboard.
I have tried this, but it didn't give me any result.
<textarea class="form-control description arabic" id="txt_desc" name="txt_desc"
placeholder="Description"></textarea>
.arabic{text-align:right;}
<script type="text/javascript">
jQuery(document).ready(function($) {
var reverseFunc = function() {
$('textarea').each(function() {
if($(this).hasClass('arabic')) {
// do the invert magic...
var val = $(this).val();
var newVal = val.charAt(val.length-1) + substr(0, val.length-1);
$(this).val(val);
}
});
}
$('textarea').bind('keyup', reverseFunc);
});
</script>
using shiftkey:
var x = document.getElementById("txt_desc");
if (event.shiftKey) {
document.getElementById('txt_desc').style.direction="rtl";
}else{
document.getElementById('txt_desc').style.direction="ltr";
}