Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

simple java math script needed

Posted on 2010-11-11
5
Medium Priority
?
307 Views
Last Modified: 2012-05-10
I am NOT a php or java programmer.  I am looking for a complete solution.

I need script that asks a question like "What do you charge for blah blah"
The user enters a dollar amount.
The script then does math based on the number entered.
The script math is a number I hard code into the script/user entered number.
Example:
User enters 125
My hard coded number is 250
Math would be 250/125

The script would then return: "Your result (or words that I would put in) is " 2 (the result of the math)

thanks.
0
Comment
Question by:glenn_1984
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:Badotz
ID: 34116298
Homework?
0
 
LVL 10

Expert Comment

by:P1ST0LPETE
ID: 34116351
Ha, that's what I was thinking Badotz.
Anyway, I'll help out:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function SimpleMath()
        {
            var num = document.getElementById('userNumber').value;
            num = num != '' ? num : 0;
            document.getElementById('result').innerHTML = 250 / num;
        }
    </script>
</head>
<body>
    <span>Enter a number:</span>
    <input id="userNumber" type="text" />
    <br />
    <a href="Javascript:SimpleMath()">Click Me</a>
    <br />
    <span>Your Result: </span>
    <span id="result" />
</body>
</html>

Open in new window

0
 
LVL 16

Author Comment

by:glenn_1984
ID: 34117026
No...homework ended decades ago.
I am a retired computer systems engineer.
0
 
LVL 16

Author Comment

by:glenn_1984
ID: 34117170
That works fine, thanks.
I would like to round the decimals to 2, however.
0
 
LVL 10

Accepted Solution

by:
P1ST0LPETE earned 2000 total points
ID: 34118054
function SimpleMath()
{
     var num = document.getElementById('userNumber').value;
     num = num != '' ? num : 0;
     var result = 250 / num;
     document.getElementById('result').innerHTML = result.toFixed(2);
}
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

972 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