We help IT Professionals succeed at work.

Jquery Calculation

Jon Imms
Jon Imms asked
on
210 Views
Last Modified: 2017-05-03
I am playing around with the Jquery slider scale,  as I want to create a custom calculation based on the slider results.

The below code, I have to sliders,  one Average Miles Per Week, and the other $ Per Mile.    I've got the sliders working, but how do you do calculations in Jquery?   In the results div, I'd like to to have the calculation Average Miles Per Week * $ Per Mile.   How would i do this ?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Slider - Snap to increments</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    $( "#slider" ).slider({
      value:100,
      min: 0,
      max: 4000,
      step: 100,
      slide: function( event, ui ) {
        $( "#amount" ).val( ui.value );
      }
    });
    $( "#amount" ).val( $( "#slider" ).slider( "value" ) );
  } );
  $( function() {
    $( "#slider2" ).slider({
      value:1,
      min: 0,
      max: 60,
      step: 1,
      slide: function( event, ui ) {
        $( "#amount2" ).val( ui.value );
      }
    });
    $( "#amount2" ).val( $( "#slider2" ).slider( "value" ) );
  } );
  </script>
</head>
<body>
 
<p>
  <label for="amount">Average Miles Per Week:</label>
  <input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
 
<div id="slider"></div>

<p>
  <label for="amount2">$ Per mile:</label>
  <input type="text" id="amount2" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>

<div id="slider2"></div>
 
<div id="result">Result  Miles Per Week * $ per mile = </div>
 
</body>
</html>

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Jon ImmsWeb Developer

Author

Commented:
Excellent,  I understand it now :) . Thanks Julian
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019

Commented:
You are welcome.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.