php - add a text field with onchange attribute to a slider -
i have got slider of internet, , want add text box slider, on value change inside slider, slider sets given value in text box.
<head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>papermashup.com | jquery ui slider demo</title> <link href="../style.css" rel="stylesheet" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script> <style type="text/css"> #container { background:url(bg.jpg)!important; padding:100px 50px 0px 50px; } /*the slider background*/ .slider { width:230px; height:11px; background:url(slider-bg.png); position:relative; margin:0; padding:0 10px; } /*style slider button*/ .ui-slider-handle { width:24px; height:24px; position:absolute; top:-7px; margin-left:-12px; z-index:200; background:url(slider-button.png); } /*result div slider value displayed*/ #slider-result { font-size:50px; height:200px; font-family:arial, helvetica, sans-serif; color:#fff; width:250px; text-align:center; text-shadow:0 1px 1px #000; font-weight:700; padding:20px 0; } /*this fill bar colour*/ .ui-widget-header { background:url(fill.png) no-repeat left; height:8px; left:1px; top:1px; position:absolute; } { outline:none; -moz-outline-style:none; } </style> </head> <body> <div class="slider"></div> <div id="slider-result">50</div> <div class="ui-widget-header"></div> <input type="hidden" id="hidden" /> <script> $(".slider").slider({ animate: true, range: "min", value: 50, min: 0, max: 80, step: 1, //this gets live reading of value , prints on page slide: function (event, ui) { $("#slider-result").html(ui.value); }, //this updates hidden form field can submit data using form change: function (event, ui) { $('#hidden').attr('value', ui.value); } }); </script> </body> </html> hope explained enough.
well you're using jquery ui. script copied can read in comments part:
slide: function (event, ui) { $("#slider-result").html(ui.value); } your result live updates.
so if little modification:
add html:
<input type="text" id="showslider" /> and modify live sliding thing/
slide: function (event, ui) { $("#slider-result").html(ui.value); $("#showslider").val(ui.value); } then thing should work.
edit:
you add event listener textbox change value each time user typing or when presses enter (that's how want it) example of this:
$("#showslider").keyup(function (e){ $(".slider").slider("value", $("#showslider").val()); } more information found here:
Comments
Post a Comment