Solved

simple java math script needed

Posted on 2010-11-11
5
296 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
Comment Utility
Homework?
0
 
LVL 10

Expert Comment

by:P1ST0LPETE
Comment Utility
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
Comment Utility
No...homework ended decades ago.
I am a retired computer systems engineer.
0
 
LVL 16

Author Comment

by:glenn_1984
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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 …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now