Solved

simple java math script needed

Posted on 2010-11-11
5
299 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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP AJAX JSON 2 61
Get Pixel color of the x and y axis Html without canvas 8 38
Getting Random number with min and max value. 2 28
alert(innerHTML); 8 19
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 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