I'm currently trying to use the following code within a form on my website
<p class="formtag">Minimum Price: </p>
<input type="number" style="width: 50px; margin-right: 15px;" name="minprice" id="minprice">
<p class="formtag">Maximum Price: </p>
<input type="number" style="width: 50px; margin-right: 15px;" name="maxprice" id="maxprice">
<p class="formtag">Show Only Free Resources </p>
<input type="checkbox" id="freecheck" onchange="disableprice()" name="freecheck" value="freeonly">
Combined with the following JavaScript
function disableprice() {
if(document.getElementById('freecheck').checked = "true") {
document.getElementById('minprice').value = "";
document.getElementById('minprice').disabled = "disabled";
document.getElementById('maxprice').value = "";
document.getElementById('maxprice').disabled = "disabled";
}
else {
document.getElementById('minprice').disabled = "false";
document.getElementById('maxprice').disabled = "false";
}
}
The idea is that if the checkbox is checked, the input fields for the maximum and minimum price are disabled, otherwise they should be editable.
The issue I am having is that once the checkbox has been checked by the user, it cannot be unchecked. I'm currently struggling to work out why this is, but I'm beginning to suspect that it has something to do with my use of the code document.getElementById('freecheck').checked = "true"
.
Can anyone please advise me on how to fix this issue?