I’m having a little problem at the moment 🙁 I’ve got a short form asking for a value of money, and below that, there’s a bit of jQuery validation which calculates 20 percent of the selected price, and subtracts it from the selected price, then updates it to the empty span tag.
The problem is, the code isn’t wrong (all the other functions in the same block work), but this does nothing, at all!
<select id="list"><option value="error">$-</option><option value="1">$1</option><option value="5">$5</option><option value="10">$10</option><option value="25">$25</option><option value="50">$50</option><option value="100">$100</option><option value="250">$250</option><option value="500">$500</option></select>
$<span id="jsprice"></span>
<script>
var price = $("#list :selected").val();
var earning = price-((price/100)*20);
$('#list').change(function(){
$('#jsprice').val(earning);
});
</script>
Does anyone know what could be wrong with this? I tried .blur() .change() and a few others, and tried
$('#jsprice').val() = earning;
but I figured that was just plain wrong, seeing as to how .text() works.
Thanks very much! Any responses greatly appreciated 🙂
this should do it.
Here is a fiddle of it http://jsfiddle.net/JeW57/