mercredi 26 août 2020

javascript using variables if statement

And please dont recommend another one cuz i tried 2 examples from there and still doesnt work. Just need something to work that string value "va"+i (va1, va2, va3 , va4, va5 etc...) can be used inside if statement even though they appear correct on the console log i cant use it on if statement

       var vu1 = document.getElementById('vu1').value; //get vu value from table
       var va1 = document.getElementById('va1').value; // get va value from table
      
        for(i = 1; i < 6; i++){ //start for loop so i can write "va"+i as (va1 etc)
        window["test"] = "va"+i; //one way of getting that va1 for if statement
        test2=window["test"]; // other way of getting that va1 for if statement
        
        var va = "va"+i;
        var vu = "vu"+i;
        var obj = {va, vu}; //another way of getting that va1 for if statement
        var key = 'va';
        console.log(obj[key]); // all those 3 console logs write the va1 to va5 correctly on consolse
        console.log(test2);
        console.log(window["test"];

        if( va1 to va5(have to say va1 here. "va"+i)  > 0){ //but isnt working this way. When try to use that variable in if statement doesnt work despite the fact that va1 appears right. should i indicate the variable differently?
            dp1 = va1/vu1;
            document.getElementById("dp1").value = dp1;
        }
    }

Aucun commentaire:

Enregistrer un commentaire