Take a look at this example: http://jsfiddle.net/LuKBm/
In practice you don’t need jQuery and you have two options. Listen to the event input
that changes with each step the mouse moves, or listen to Event mouseup
that shoots only when mouse raises.
The code of the example is:
var p = document.getElementById("price"),
res1 = document.getElementById("resultado1"),
res2 = document.getElementById("resultado2");
p.addEventListener("input", function () {
res1.innerHTML = "€" + p.value;
}, false);
p.addEventListener("mouseup", function () {
res2.innerHTML = "€" + p.value;
}, false);
But if you want to use jQuery, in some cases it can have advantages, so what you need is:
$('seletorElemento') // um seletor CSS
.on('mouseup', // quando ocorrer um mouse up naquele elemento... (pode também usar o "input"
function(){
// aqui pode correr o código que precisa, por exemplo mostrar o valor
$('outroElemento').html(this.value); // no caso de querer mudar o html
});
Without the comments:
$('#price').on('mouseup', function () {
$('#resultado1').html(this.value);
});
Great example, works great. here comes another question if for example it is necessary to insert a decimal value containing numbers with the proper commas for financial values, have any hints? Thank you.
– the flash
@theflash take a look at this answer: http://answall.com/a/14729/129
– Sergio
@theflash: to use decimal places you can use so: http://jsfiddle.net/zmW3T/
– Sergio
I checked the link sent @Rgio
– the flash
@theflash, ok. Did that answer your question? if not put more information than you need
– Sergio
is really where my doubt was, thanks for the help!
– the flash