Within my models.py file, I've defined the following:
urgency = models.BooleanField(blank=True, default=False, verbose_name="Hitno otklanjanje")
I am attempting to execute a javascript function that will modify a text field based on whether the Boolean field is set to 'True' or 'False'. However, I'm encountering an issue where I am unable to retrieve the value. Whenever I utilize
document.getElementById('id_urgency').value;
, it consistently returns 'on', regardless of whether the checkbox is checked or not. What could be causing this? Am I misinterpreting the value?
<script type="text/javascript">
function makeReadOnly()
{
var a = document.getElementById('id_urgency').value;
console.log(a);
if (document.getElementById('id_urgency').value == 'True'){
document.getElementById('id_date_days').readOnly = true;
}else if (document.getElementById('id_urgency').value == 'False'){
document.getElementById('id_date_days').readOnly = false;
}
}
document.getElementById('id_urgency').addEventListener('change', makeReadOnly);
This code snippet is part of a Django form. Upon inspecting the page, I noticed that the Checkbox element does not have a value assigned to it. Why might this be the case?
input type="checkbox" name="urgency" class="checkboxinput form-check-input" id="id_urgency"