Link to home
Start Free TrialLog in
Avatar of mounty95
mounty95Flag for United States of America

asked on

Javascript If Then Return Value

I am stuck on what I have a feeling is a pretty simple JS.

I have a button that when clicked does a calculation based on form fields and returns a numeric value.

I would like to add an additional field to evaluate the numeric value and return a description like "Superior" "Good" "Adequate" etc.

How do I write a separate formula to return the description by evaluating the calculated number field something like:  if score less than 75 then Poor else if score between 75 and 80 then Not Adequate so on and so forth.

Thank you in advance for any help on this.
Avatar of Gary
Gary
Flag of Ireland image

Need some context for a proper answer but something like this

function getdescription(score){
     if(score<=100){getdescription="Superior"}
     if(score<=80){getdescription="Good"}
     if(score<=75){getdescription="Adequate"}
     return getdescription
}
Avatar of mounty95

ASKER

What do your mean context?  

I have a button that the user clicks after filling out a form.  The value is returned in a textbox with id="s".

I want to evaluate the value in the textbox and return in a separate textbox a descriptor for that calculation.
Context is giving us some code and not just saying I have a button.

Why evaluate the textbox, just work out the description (using code like above) when the button is pressed.
Here is the formula that returns a value:

function calc(thisform)
{
var rf=thisform.rf.value;
var ap=thisform.ap.value;
var ts=thisform.ts.value;
thisform.s.value=math.round(rf+ap+ts)

How would I (in the same code) evaluate so that the value in s and a description get returned?

Sorry to be so vague.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for your help.