lundi 24 septembre 2018

i want to change color of students label according to marks from input text-box but there is problem in my java-script code

<script type="text/javascript">
var students = document.querySelectorAll("#student");
var label = document.querySelectorAll("label");
var button = document.querySelector("button");

button.addEventListener("click",function(){
    for(var i = 0; i < students.length; i++){
        for(var j = 0; j < label.length; j++){
            if (students[i].value >= 70 && students[i].value <= 100){
                label[j].style.backgroundColor = "green";
            }else if (students[i].value >= 50 && students[i].value < 70){
                label[j].style.backgroundColor = "blue";                
            }else if (students[i].value >= 35 && students[i].value < 50){
                label[j].style.backgroundColor = "yellow";
            }else{
                label[j].style.backgroundColor = "red";
            }
        }
    }
});
</script>

/There is Problem in java-script code and for loops/ /Selecting elements from HTML works fine/

Aucun commentaire:

Enregistrer un commentaire