Jquery Slider not updating input fields live
Hi I am trying to make a quote generation tool using multiple sliders but for some reason the totals do not update 100% on one slider until you use the other, then vise verser . I have tried many things but am missing something here and hope that someone can help, here is the code:
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <title></title>
- <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
- <link rel="stylesheet" href="/resources/demos/style.css" />
- <script>
- $(document).ready(function(){
-
- function update() {
- var ram = $('#ram').slider('value');
- var disk = $('#disk').slider('value');
- var ramval = (ram * 0.25);
- var diskval = (disk * 0.10);
- var monthly = (ramval + diskval);
- $("#monthly").text(monthly.toFixed(2));
- $("#ramres").text(ram.toFixed(0));
- $("#diskres").text(disk.toFixed(0));
- }
- $("#ram").slider({
- value: 0,
- min: 1,
- max: 32,
- step: 1,
- slide: function() {
- update();
- }
-
- });
- $("#disk").slider({
- value: 100,
- min: 100,
- max: 1000,
- step: 100,
- slide: function() {
- update();
- }
-
- });
- update();
- });
- </script>
- </head>
- <body>
- <div style="width:500px; margin-left:200px; float:left;">
- <h2>Ram: <span id="ramres">1</span>GB</h2>
- <div id="ram"></div>
- <h2>Disk Space: <span id="diskres">100</span>GB</h2>
- <div id="disk"></div>
- <h2>Result</h2>
- Total £<span id="monthly">0</span>
- </div>
- <div style="width:500px; margin-left:200px; float:left;">
- </div>
- </body>
- </html>