mercredi 14 septembre 2016

Javascript: If statement - two variables?

I am trying to check if level is something and degree is something, then total is a value of certain field. The code only works for Example 1 which makes me think I need degree in the variable.

Examples:

  • level = 1; degree = Terminal; 1_T = 205
  • level = 2; degree = NonTerminal; 2_NT = 230
 $(document).ready(function(){
      $(".level input" && ".degree input").change(function(){
        var level = $(".level input").val();

        if (level == "1" || degree == "Terminal"){
          $(".total input").val($(".1_T input").val());
        }
        else if (level == "2" || degree == "NonTerminal") {
          $(".total input").val($(".2_NT input").val());
        }
        });
    })

What am I doing wrong? I was trying to figure out if there was a way to define a second variable like on line 3 I did with level there should probably something that defines the degree.

Aucun commentaire:

Enregistrer un commentaire