3

I have a Time Textbox with a mask. Mask is shown in textbox as 00:00

So user types in digits over the mask.

Now customer says he does not want to type in letter from left to right. He wants to type from right to left.

Similar to what we have in calculator.

Now I tried changing the textbox's righttoleft property but that does not help my cause.

Can anyone help me out in achieving this functionality using jquery

Vidhya
  • 31
  • 3
  • possible duplicate of [Right to left Text HTML input](http://stackoverflow.com/questions/7524855/right-to-left-text-html-input) – MrClan Jan 23 '14 at 17:48

2 Answers2

2

Add the below css style to your input textbox:

.time
{
    direction: rtl;
}

It changes the textbox behavior to right-to-left.

Soundar
  • 2,569
  • 1
  • 16
  • 24
0

Not jQuery, but CSS:

.myInput {  text-align: right; }

That throws the text to the right. Now, to get fancier than that, you'll need to do some javascript logic to flip the characters around.

Any easy way to to turn the string into an Array, then reverse it, then reassemble:

var flippedText = String(text).split('').reverse().join('');

That isn't necessarily the most efficient means, but it should fit your usage fine.


That character flipping is going to have to happen every time someone types, so to be true and use jQuery:

$('.myInput').on('keypress', function(){
  var text = $(this).val();
  String(text).trim().split('').reverse().join('');            
});
dthree
  • 19,847
  • 14
  • 77
  • 106