submit button gets enabled when I type date manually but when I select it from datepicker it does not gets enabled
<html>
<body>
<input type="date" id="txt" onkeyup="manage(this)" name=<?php echo 'actual_date__' . $cur['id'] . '__' . $cur['master_id'] ?> value="<?php echo $filtered_row_result1["actual_date"] ?? ''; ?>" >
<input type="submit" id="btSubmit" disabled />
</body>
<script>
function manage(txt) {
var bt = document.getElementById('btSubmit');
if (txt.value != '') {
bt.disabled = false;
}
else {
bt.disabled = true;
}
}
<script>
</html>
CodePudding user response:
<html>
<body>
<input type="date" id="txt" onchange="manage(this)" name="_name" value="1990-01-01" >
<input type="submit" id="btSubmit" disabled />
</body>
<script>
function manage(txt) {
console.log(txt);
let bt = document.getElementById('btSubmit');
if (txt.value != '') {
bt.disabled = false;
}
else {
bt.disabled = true;
}
}
</script>
</html>
check out this solution. I changed the input name - because I can't use php here. change to yours
CodePudding user response:
Use onchange instead of onkeyup
function manage(txt) {
var bt = document.getElementById('btSubmit');
if (txt.value != '') {
bt.disabled = false;
} else {
bt.disabled = true;
}
}
<html>
<body>
<input type="date" id="txt" onchange="manage(this)" name=<?php echo 'actual_date__' . $cur[ 'id'] . '__' . $cur[ 'master_id'] ?> value="
<?php echo $filtered_row_result1["actual_date"] ?? ''; ?>" >
<input type="submit" id="btSubmit" disabled />
</body>
</html>