Link to home
Start Free TrialLog in
Avatar of Glenn Abelson
Glenn AbelsonFlag for United States of America

asked on

simple java math script needed

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.
Avatar of Badotz
Badotz
Flag of United States of America image

Homework?
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

Avatar of Glenn Abelson

ASKER

No...homework ended decades ago.
I am a retired computer systems engineer.
That works fine, thanks.
I would like to round the decimals to 2, however.
ASKER CERTIFIED SOLUTION
Avatar of P1ST0LPETE
P1ST0LPETE
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial