mardi 15 novembre 2016

function with if/else statement on a form

I am new to JavaScript, so this is one of my learning projects, but after a lot of research, I am stuck. Could someone tell me where I am going wrong? I can't seem to get a result to show up in the second text box after the first question is submitted. The two id's are in my html.

function myFunction(age1, level1) {

  var age1 = document.getElementById("age").value;
  var level1 = document.getElementById("level").value;

if (age1 <= 20) {
  level1.value = 1;
}
else if(age1 <= 40) {
  level1.value = 2;
}
else {
  level1.value = 3;
}
}

Aucun commentaire:

Enregistrer un commentaire