I have a span with a text in it that suppose to change constantly after I press something in my textbox.
<input type="text" class="response" onkeypress="return ChangeSpan()" id="how_many" name="how_many" placeholder="Enter how many..." />
and my jQuery:
<script type="text/javascript">
function ChangeSpan() {
var text = $("#how_many").val();
$('#changeText').text(text);
}
</script>
it’s working perfectly fine , but when I press let’s say "dfg" , its only present "df" on the span. and only when I add the next charecter, it adds the "g".
I want it to respond also to the last character, how do I do that ?
You probably want to use keyup.
You use jQuery and add the events inline? That is bad practice. Attach events using on.
Difference between keyup, keydown, and keypress explained on quirksmode.