javascript - use multiple live slider on html with jquery -
i new javascript , want solve following problem. html code below shows 2 live slider inputs in 1 form. 1 working. ( source: live output in jquery html5 range slider)
so how can use multiple sliders different values on same web page?
$("#rangevalue").mousemove(function () { $("#text").text($("#rangevalue").val()) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <!doctype html> <html> <head><title>timing:</title></head> <body> <h1>timing:</h1> <form action="/cgi-bin/can/test.cgi" method="post"> <table style="width:300px" border="1"> <th>time</th> <tr> <td> <input type="range" name="p" value=16.08 min=0.01 max=32.08 id="rangevalue" step ="0.01"><label id="text" >16.08</label> </td> </tr> <tr> <td> <input type="range" name="p" value=100 min=50 max=150 id="rangevalue" step ="0.01"><label id="text">100</label> sec. </td> </tr> </table> <br><input style="font-size:25px" type="submit" value="start"> </form> </body> </html>
the issue because have duplicated id
attributes in html when must unique. need convert code use classes instead.
to can select rangevalue
elements, , use .next()
find related .text
element, this:
$(".rangevalue").on('change mousemove', function() { $(this).next(".text").text(this.value) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table style="width:300px" border="1"> <th>time</th> <tr> <td> <input type="range" name="p" value="16.08" min="0.01" max="32.08" class="rangevalue" step="0.01"> <label class="text">16.08</label> </td> </tr> <tr> <td> <input type="range" name="p" value="100" min="50" max="150" class="rangevalue" step="0.01"> <label class="text">100</label>sec. </td> </tr> </table>
Comments
Post a Comment