Passing javascript slider value to hidden input

Reply

Join Date: Dec 2008
Posts: 1
Reputation: djthekid is an unknown quantity at this point 
Solved Threads: 0
djthekid djthekid is offline Offline
Newbie Poster

Passing javascript slider value to hidden input

 
0
  #1
Dec 17th, 2008
I need some help here please.
I have a form that has a javascript slider bar to give one field's percentage.
Unfortunately I can't get the value to pass to the hidden input.
Here's the code:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3.  
  4. <html>
  5. <head>
  6. <title>Slider test</title>
  7. <script type="text/javascript" src="configs/prototype.js"></script>
  8. <script type="text/javascript" src="configs/scriptaculous.js"></script>
  9.  
  10.  
  11. </head>
  12.  
  13. <body>
  14.  
  15. <p>Slider works with a click on the track, pulling the handle, or the mouse wheel.</p>
  16. <form action="<? $SERVER['PHP_SELF'] ?>" method="post">
  17.  
  18. <div id="slider">
  19.  
  20. <div id="slider-bar">
  21.  
  22. <div id="slider-handle"><p id="percent">//The percentage shows here!!../</p></div>
  23.  
  24. </div>
  25.  
  26. </div>
  27. <br />
  28. <br />
  29.  
  30. <input type="hidden" id="percent" onkeyup="setSlideOutput(slide, this.value);" name="effectiveness" onchange="setSlideOutput(slide, this.value);" value="" />
  31.  
  32. <script type="text/javascript">
  33. // <![CDATA[
  34. var hWidth, bWidth, slide;
  35.  
  36. function setBgPos(v) {
  37. var off = v * hWidth;
  38. var pos = -bWidth + (v * bWidth);
  39. $('slider').setStyle({backgroundPosition: Math.round(pos - off) + 'px'});
  40. }
  41.  
  42. function setSlideOutput(v) {
  43. $('percent').update(Math.round(v * 100) + '%');
  44. }
  45.  
  46. Event.observe(window, 'load', function() {
  47. hWidth = $('slider-handle').getWidth();
  48. bWidth = $('slider-bar').getWidth();
  49. slide = new Control.Slider('slider-handle', 'slider-bar', {
  50. sliderValue: 0.10,
  51. onSlide:
  52. function(v) {
  53. setBgPos(v);
  54. setSlideOutput(v);
  55. },
  56. onChange:
  57. function(v) {
  58. setBgPos(v);
  59. setSlideOutput(v);
  60. }
  61. });
  62. setBgPos(slide.value);
  63. setSlideOutput(slide.value);
  64. Event.observe('slider', 'mousewheel', function(e) {
  65. slide.setValueBy((Event.wheel(e)/20));
  66. });
  67. });
  68. // ]]>
  69. </script>
  70. <style type="text/css">
  71. @import url(configs/slider.css);
  72. body {
  73. font-family: arial, verdana, sans-serif;
  74. }
  75. </style>
  76.  
  77.  
  78. <input name="status" type="hidden" value="1" />
  79. <input type="button" value="Change Info" onclick="javascript:history.go(-1)" />
  80. <input type="submit" class="btn green" value="Submit" />
  81. </form>
  82.  
  83. <? echo $_POST['effectiveness'] ?>
  84.  
  85. <div id="debug"></div>
  86. <? ?>
  87. </body>
  88. </html>
Last edited by peter_budo; Dec 17th, 2008 at 8:03 pm. Reason: Correcting code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC