Jquery Slider not updating input fields live

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:

  1. <html lang="en">
  2. <head>
  3.   <meta charset="utf-8" />
  4.   <title></title>
  5.   <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
  6. <script src="http://code.jquery.com/jquery-latest.js"></script>
  7.   <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
  8.   <link rel="stylesheet" href="/resources/demos/style.css" />
  9.   <script>
  10.   $(document).ready(function(){
  11.   
  12. function update() {
  13.     var ram = $('#ram').slider('value');
  14.     var disk = $('#disk').slider('value');
  15. var ramval = (ram * 0.25);
  16. var diskval = (disk * 0.10);
  17.     var monthly = (ramval + diskval);
  18.     $("#monthly").text(monthly.toFixed(2));
  19. $("#ramres").text(ram.toFixed(0));
  20. $("#diskres").text(disk.toFixed(0));
  21. }

  22. $("#ram").slider({
  23.     value: 0,
  24.     min: 1,
  25.     max: 32,
  26.     step: 1,
  27.     slide: function() {
  28.         update();
  29.     }
  30. });

  31. $("#disk").slider({
  32.     value: 100,
  33.     min: 100,
  34.     max: 1000,
  35.     step: 100,
  36.     slide: function() {
  37.         update();
  38.     }
  39. });
  40. update();
  41. });
  42.   </script>
  43. </head>
  44. <body>
  45. <div style="width:500px; margin-left:200px; float:left;">
  46. <h2>Ram: <span id="ramres">1</span>GB</h2>
  47. <div id="ram"></div>

  48. <h2>Disk Space: <span id="diskres">100</span>GB</h2>
  49. <div id="disk"></div>

  50. <h2>Result</h2>
  51. Total &pound;<span id="monthly">0</span>

  52. </div>
  53. <div style="width:500px; margin-left:200px; float:left;">

  54. </div>
  55. </body>
  56. </html>