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

x
?
Solved

simple java math script needed

Posted on 2010-11-11
5
Medium Priority
?
304 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
[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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

722 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