Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript If Then Return Value

Posted on 2013-10-29
6
Medium Priority
?
230 Views
Last Modified: 2013-10-29
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.
0
Comment
Question by:mounty95
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39609561
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
}
0
 

Author Comment

by:mounty95
ID: 39609568
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.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39609571
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.
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

Author Comment

by:mounty95
ID: 39609669
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.
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39609685
function calc(thisform)
{
var rf=thisform.rf.value;
var ap=thisform.ap.value;
var ts=thisform.ts.value;
totalscore=math.round(rf+ap+ts)
thisform.s.value=totalscore

// amend these as necessary
     if(totalscore<=100){description="Superior"}
     if(totalscore<=80){description="Good"}
     if(totalscore<=75){description="Adequate"}
// add a text box to the form and assign it an id and change it below.
document.getElementById("mytextbox").value=description
}
0
 

Author Closing Comment

by:mounty95
ID: 39609714
Thank you for your help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question