how do you make fractions in a form

I need to be able to let user input fractions into a form field and then add them.


Cory Zickert


4 Answers

You will have to use custom JavaScript and possibly include additional scripts for keystroke and validation.

If the values will be whole numbers and fractions, then your need to split the values into whole number and fractions and then create a decimal value.

You will also need to convert the decimal result back to fractions.


George Kaiser   

Could you be more specific? How many sets of fractions do you want the user to enter? Unlimited? How do you want the user to separate the fractions inside the field? This could get very complex, and will probably involve most of what George mentioned. It definitely doesn't sound impossible based on your question, but if you're not comfortable with in-depth javascript you may want to find a willing person with some spare time to help you. Or, you could hire someone to do this for a small fee.


Lane Pemberton   

A sample of one possible way, but it only returns a decimal number:

var Fraction1 = "1+3/4";
var Fraction2 = "2+1/8";
app.alert(Fraction1 + " + " + Fraction2 + " = " + (eval(Fraction1)+ eval(Fraction2)), 3, 0);


George Kaiser   

I figured it out!...I think. I built a field that accepts two fractions seperated by a comma, adds them up, and then reduces the resulting fraction. Is this what you're looking for? Is there any other functionality you'd like to see?


Lane Pemberton   


Please specify a reason: