I'm trying enable/disable an input button with a simple if
condition in jQuery but somehow the if
is working but the else if
won't work. I'm trying to enable the input button in a range between 0 - 40. The button enables when putting in a number above 0 but won't disable when I'm above 40. What am I doing wrong?
$(document).ready(function() {
$('#btn').prop('disabled', true);
$('#temp').keyup(function() {
if ($('#temp').val() > '40') {
$('#btn').prop('disabled', true);
} else if ($('#temp').val() > '0') {
$('#btn').prop('disabled', false);
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form method="POST" action="/mainpage">
<div>
<label>Temperatur in <strong>°C</strong>:</label>
<input type="number" id="temp" name='temperatur'> </input>
<input type="submit" id="btn" class="btn btn-info btn-lg" name="button" value="Weiter">
</div>
</form>