1

I am trying to create fractions in an editbox, or textbox using javascript, such as 5/9

In other words, if I could create a temp string of the fraction format of “5/9”, the code would be:

editbox.value=temp;

I am aware that the html code would be:

<sup>5</sup>&frasl;<sup>9</sup> 

I am also aware that the javascript way of changing to a superscript is to use .sup

The Unicode for a fraction slash is "\u2044"

However, if I use the following code:

var temp1 =  "5" ;
temp1=temp1.sup();
var temp2 =  "9" ; 
temp2=temp2.sup();
temp="\u2044";
temp=temp1+temp+temp2;
player.value=temp;

It just gives :" sup>5 /sup>⁄ sup>9 /sup> "

Furthermore, although there are unicodes for superscripts of single digit numbers, there are no unicodes for subscripts, so the result is unreadable as a fraction.

Can anyone help?

IanR
  • 31
  • 1
  • 5
  • You probably can't. Even if you could, how would a user edit the fraction? Maybe you should just take plain ASCII text (e.g., `5/9`), parse it as a fraction, and display it as such in HTML (e.g., `59`). – Heretic Monkey Apr 14 '20 at 20:07
  • Thanks for the reply. In my case the user does not need to alter it. It is a question in a quiz, and historically that question is displayed in an editbox. Unfortunately, I cannot display the html code in the editbox. – IanR Apr 15 '20 at 06:54
  • You can use a `` or `
    ` tag an style it to look like an "editbox" if you must... [How do I make an editable DIV look like a text field?](https://stackoverflow.com/q/8956567/215552) (ignore the "editable" part).
    – Heretic Monkey Apr 15 '20 at 12:25
  • Thanks again for your reply. Unfortunately, I have the reverse problem. The code in the quiz is quite complex (over 6000 lines) and the .value of the editbox is called all over the place. So it is not really an option to change the editbox to a div. I assume there is no way to put a small object (eg a div with html code) inside a line of text in the editbox. However, thanks again for your time. I appreciate it. – IanR Apr 15 '20 at 17:52

0 Answers0