jeudi 26 mai 2016

Javascript incrementing by more than one

var x1 = document.getElementById("x1");    
var x2 = document.getElementById("x2");

function ThisEvent(){// needs a lot of work done to it
  if (x1.value==1) {
    x2.value--;
  } else if (x1.value==2) {
    x2.value++;
  } else if (x1.value==3) {
    x2.value+=5;
  }
}
<input type="text" value="0" id="x1" onblur="ThisEvent()"> x1     </br>   
<input type="text" value="0" id="x2"> x2

what is happening now is the digit is being added instead of incrementing when 3 is the input if x1. how do you make it increment by more than just one, without it being added it as a digit?

Aucun commentaire:

Enregistrer un commentaire