html - JQuery: Operations on output value, but still keeping it printing as user types -
in html have this:
<input type="text" name="earned" id="earned"> <p>you have: $<span id="amount"></span></p>
and in javascript file have this:
$(function(){ $('#earned').keyup(function(){ var $earned = this; $earned = $earned/100; $('#amount').text($(earned).val()+ '.00'); }); });
i wrote code simple calculator. if wanted grab user typing , change typed, how go this? how come dividing 100 doesn't work? outputs number being typed in.
$('#earned').keyup(function(){ var $earned = parseint($(this).val(), 10)/100; // .val() here $('#amount').html($earned+ '.00'); // variable here });
the this
refers dom input field. need jquery object of , .val()
of input field. parse integer, because strings can't divided. , set output span.
Comments
Post a Comment