Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

Add html attribute if the input value meet requirements

$
0
0

Let say I have two input. When I key-in value in input1 for example 0.4 and meets the requirement then the input2 will remove the readonly attribute. Meanwhile if I input value in input1 is 0.3 then the input2 attribute will become readonly again.

It doesnt work. Maybe i missed out anything here

$(".input1").keydown(function() {
    var dInput = $(this).val();
    if (dInput >= 0.4 && dInput <= 0.6) {
        $(".input2").attr('readonly', true);
    } else {
        $(".input2").removeAttr("readonly");
    }
});

function isNumberKey(e) { // stub
    return true;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><input type="text" class="input1" onkeypress="return isNumberKey(event)" id="input1" name="input1" value="" /><input type="text" class="input2" onkeypress="return isNumberKey(event)" id="input2" name="input2" value="" readonly />

Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>