I am trying to change text of one div, when I enter different values into my text input:
EXAMPLE:
Input = 1,
DIV TEXT: "rok" //in eng. "year"
Input = 2,
DIV TEXT: "roky"
Input = 3,
DIV TEXT: "roky"
Input = 4,
DIV TEXT: "roky"
Input = 5,
DIV TEXT: "rokov"
Default value of my input is 3.
html
<input type="text" id="pocetrokov" value="3"><span id="year">roky</span>
Js:
function rok() {
if(roky==2 || roky==3 || roky==4){
$('#year').html('roky');
} else if( roky>4 || roky == 0){
$('#year').html('rokov');
} else if (roky==1){
$('#year').html('rok');
}
}
$(function () {
$('select, input').on('keydown blur change', rok);
});
I get this when I change the defalut value:
Input = 1,
DIV TEXT ="rokov" instead of "rok"
Input = 2,
DIV TEXT ="rokov" instead of "rok"
... etc.
I get the correct value only when I click somehere outside the input
What is wrong? Thank you.