Skip to content
Advertisement

Changing the value of input-box with respect of another input-box?

I am doing something wrong.

html:

Quantity: <input type = "text" id ="quantc" name = "quantWash" size = "5" tabindex = "13" onblur="calcRowWash()"/><br>
Wash Total: <input type = "text" id ="totc" name = "washtotal" size = "5" tabindex = "14" value=""/>

js:

    calcRowWash = (function(){ 
        var x = document.getElementById("quantc");

        if(x == "2"){
            document.getElementById("totc").value = 1000;
        }else{
            document.getElementById("totc").value = 100;
        }

});


http://jsfiddle.net/nwxtrqjb/

Advertisement

Answer

There you go, it is working now. As mentioned by Alon, you were comparing the element itself (#quantc) instead of its value

calcRowWash = (function(){ 
   var x = document.getElementById("quantc").value;
        if(x == "2"){
            document.getElementById("totc").value = 1000;
        }else{
            document.getElementById("totc").value = 100;
        }

});
Quantity: <input type = "text" id ="quantc" name = "quantWash" size = "5" tabindex = "13" onblur="calcRowWash()"/><br>
Wash Total: <input type = "text" id ="totc" name = "washtotal" size = "5" tabindex = "14" value=""/>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement