Introduction

I started looking for a way to type numbers backwards on a computer so that I could create an offline JavaScript app for practicing a multiplication technique that requires the answer to be typed in from right to left, from the ones digits up through the higher place-value digits of the answer. The final answer is read normally from left to right, but the answer is typed or hand-written from right to left, all on one line. It is called the "Criss-Cross System of Multiplication". I learned the method from the book Vedic Mathematics Made Easy, by Djaval Bathia. The relevant chapter can be downloaded for free.

My first problem was that I did not know how to type numbers backwards.

Ms. Moriel Schottlender

After researching online, I found writings and videos by Ms. Moriel Schottlender, Principal Engineer at Wikimedia Foundation, who is a specialist in how to display content in Wikipedia articles that use right-to-left languages like Hebrew, Arabic, or Persian. I contacted Ms. Schottlender by email and I explained my reason for wanting to type numbers backwards, and she replied immediately and solved my problem. The HTML tags <bdo dir="rtl" contenteditable></bdo>, when used with CSS to create a text entry area, will display any typed-in contents in reverse, both letters and numbers.

Ms. Schottlender gained her expertise by solving problems that arise when presenting right-to-left languages (like Hebrew, Arabic, or Persian) alongside left-to-right languages (like English) in Wikipedia pages and in software. Ms. Schottlender explains that displaying a mix of languages written in opposing directions on a webpage can be difficult because different browsers are not consistent in how they display changing directions of text. She describes her work as "system localization, supporting your user no matter where they are, and human-centered development."  Ms. Schottlender emphasizes, "I create human-centered software", and her work assisting with correctly-formatted written communication in webpages and software presenting multiple languages written in different directions certainly qualifies as a human-centered endeavor to help people understand and communicate with each other. Visit moriel.tech

Typing numbers backwards was the sine quo non of my desired "criss-cross" multiplication practice app, and Ms. Schottlender gave me a quick and easy solution. Thank you, Ms. Moriel Schottlender.

A photo of Moriel Schottlender, a.k.a 'mooeypoo', who is a senior software engineer at Wikipedia
Ms. Moriel Schottlender,
Principal Engineer at Wikimedia
Many Other Ways

All HTML tags that can display numbers and text can display the content in reverse order. In the non-exhaustive examples below, HTML tags that can display text and numbers backwards are first displayed as code examples and are then followed by editable fields created with those HTML tags to allow experimental editing by the reader. A button is provided after each editable field to clear any editing, and a final button is provided after all the editable fields to clear all the editing fields at once. Notes accompanying each HTML tag example will point out normal and odd behaviors.

However, for HTML tags to create a visible field on a webpage, CSS style declarations must state the height, width, and background color associated with the tags to create a rectangular area on the webpage (even if the background color is "none" or "transparent"). Border lines around the rectangle should also be declared to make it easier to see the rectangle. Further, many such rectangles will not be exteriorly editable unless the opening HTML tag is embedded with the boolean attribute statement of either contenteditable or contenteditable="true" (either works). Most HTML tags also need the CSS declaration of unicode-bidi: bidi-override; which reverses the direction of text from the normal order on the user's computer, whether that is forward or backward. However, there is one set of HTML tags that have the unicode-bidi: bidi-override; property by default, the <bdo></bdo> tags provided to me by Ms. Moriel Schottlender. Finally, the CSS declaration of direction: rtl; is needed to start typing backwards from the right side of an editable field that has the CSS declaration of unicode-bidi: bidi-override; or that default property. Otherwise, without that CSS declaration of direction: rtl;, the content will be displayed in reverse order by pushing content from off the left side of the entry field without the cursor ever moving, which looks strange and would not be usable for my "Criss-Cross" Multiplication Practiceware which must have numbers typed backwards and away from the right side of the entry field.

Each example set of HTML tags below will show an embedded class attribute statement of either class="bidi" or class="noBidi". All the other CSS style declarations under both classes are the same:

 .bidi {      
    direction: rtl;
    unicode-bidi: bidi-override;
    width: 300px;
    height: 30px;
    background-color: none;
    border: 2px solid black;
    display: inline-block;
    padding: 5px;
    padding-bottom: 0;
    margin: 15px;
    margin-top: 5px;
    overflow: hidden;    
 }

 .noBidi {
    direction: rtl;
    display: inline-block;
    width: 300px;
    height: 30px;    
    background-color: none;
    border: 2px solid black;
    padding: 5px;
    padding-bottom: 0;
    margin: 15px;
    margin-top: 5px;
    overflow: hidden;     
 }             
        

Now for the examples:

<bdo class="noBidi" contenteditable></bdo>
Approved by Ms. Moriel Schottlender, the <bdo contenteditable></bdo> tags do not need the CSS declaration of unicode-bidi: bidi-override; to present contents in reverse, and the text entry areas are always exteriorly editable with no odd behaviors. Click to edit:

<div class="bidi" contenteditable></div>
The <div contenteditable></div> tags need the CSS declaration of unicode-bidi: bidi-override; to present contents in reverse, but the text entry areas are always exteriorly editable with no odd behaviors. Click to edit:

<p class="bidi" contenteditable></p>
The <p contenteditable></p> tags need the CSS declaration of unicode-bidi: bidi-override; to present contents in reverse, but the text entry areas are always exteriorly editable with no odd behaviors. Click to edit:


<span class="bidi" contenteditable></span>
The <span contenteditable></span> tags need the CSS declaration of unicode-bidi: bidi-override; to present contents in reverse, but the text entry areas are always exteriorly editable with no odd behaviors. Click to edit:

<button class="bidi" contenteditable>tide dna txet nottub kcilc</button>
The <button contenteditable></button> tags need the CSS declaration of unicode-bidi: bidi-override; to present contents in reverse, but those tags ignore CSS declarations about the size of the text area and the background color. Further, the tags must already have text in between the tags (their inner HTML) to display exteriorly editable text, and that text must be clicked right before the first letter, or right after the last letter, or anywhere in between, for the text to be exteriorly editable. Otherwise, any click in pure whitespace (grayspace) does not provide cursor focus. Finally, if the text is edited to blank and cursor focus is lost by clicking elsewhere with a new cursor focus, the old cursor focus cannot be reestablished for further editing. Click within or right next to the displayed text to edit:

<input type="button" class="bidi" value="9876543210" contenteditable>
The <input type="button" contenteditable value="9876543210"> tag needs the CSS declaration of unicode-bidi: bidi-override; to present the quoted contents of its value attribute in reverse, but the tag ignores CSS declarations about the size of the text area and the background color. The tag has no closing tag, and hence no inner HTML between the opening and closing tag, and so it is called a void element (no inner HTML). Although the quoted contents of the tag's value attribute is displayed backwards as desired, the text from inside the value attribute is not exteriorly editable. Try clicking to edit:

While searching for alternate ways of displaying content backwards, I chanced upon Unicode codepoint &#x202E;, which can be written in between any opening and closing HTML tags that can display text, and then all subsequent content inside the tags or added with exterior editing will be displayed backwards on the webpage without needing the CSS declaration of unicode-bidi: bidi-override;. (There is a sister codepoint &#x202D; that will display all subsequent text forward.)

<div class="noBidi" contenteditable>&#x202E;</div>
The <div contenteditable>&#x202E;</div> tags with the reverse-display codepoint &#x202E; coded inside the tags do not need the CSS declaration of unicode-bidi: bidi-override; to present contents in reverse. However, the codepoint &#x202E; can be accidentally deleted from the underlying inner HTML by backspacing one more time after using backspace to exteriorly edit and remove all previously inserted contents. Further, even with the codepoint &#x202E; still intact, clicking at the farthest right edge in the text entry area and then adding content will insert that content at a position in the inner HTML before the reverse-display codepoint; and, thus, that content will not display in reverse order. These errors were haphazard (sometimes occurring, sometimes not) and were hard to figure out until I used the Chrome developer tools to zero in on the div element while making entries and backspacing out the content. The reverse-display codepoint method is currently too error-prone to be reliable. The Reset Button adds the codepoint &#x202E; back into the div if it has been accidentally removed, but content that is accidentally inserted before the reverse-display codepoint would need another solution. Click to edit:
‮

Before Ms. Moriel Schottlender had given me a way to type numbers backwards with the <bdo></bdo> tags, I had thought that I might have to use JavaScript to immediately display each number in reverse order after each number is typed. Every programming language has a routine way of reversing the digits of a number. See, the linked geeksforgeeks.org article. However, such methods reverse a whole number rather than immediately displaying each number in reverse order as each number is typed.

The text-entry area below uses JavaScript code to append each new number to a string of any previously typed numbers, and then the reverse-display codepoint (&#x202E;) is concatenated before each updated string of numbers, and the current result is displayed after each new number is typed. As such, each newly typed number is immediately displayed in reverse order along with any previous numbers. A regular expression is used to filter out any entries that are not numbers.

Although the program works, it does not—as now written—allow common editing techniques like using the backspace key to remove numbers from the text-entry field. Even so, the program is a paradigm for how to alter typed-in entries using JavaScript and then immediately redisplay the content, thus effectively creating a little word processor.

<div class="noBidi" id="applet" contenteditable></div>
Click and enter numbers:

The JavaScript code:
  <script type="text/javascript">

      let str$ = "";
      let reverseCodepoint$ = "&#x202E;";
      let display$ = "";

      applet.addEventListener('keydown', (event) => {
        event.preventDefault();
        if (/^\d$/.test(event.key)) {
            str$ = str$.concat(event.key);
            display$ = (reverseCodepoint + str$);
            applet.innerHTML = display$;
        }
      });

  </script>

Click to reset all the above editing fields:

"Criss-Cross" Multiplication

The steps below show how to use the "criss-cross" method for multiplying a two-digit number by a two-digit number (here, 27 x 38):