I am trying to hide a radiobutton if there is no value given to the form label for this radio. i am using flask and when i load the page, i check if a harddrive is connected, and if not, there should not be an option to check anything.
Python
@app.route('/transfer')
def transfer():
hardDrive = transfer_files.find_harddrive()
if len(hardDrive) == 1:
hardDrive1 = hardDrive[0]
hardDrive2 = ''
elif len(hardDrive) == 2:
hardDrive1 = hardDrive[0]
hardDrive2 = hardDrive[1]
else:
hardDrive1 = ''
hardDrive2 = ''
return render_template("transfer.html", usb_device1=hardDrive1, usb_device2=hardDrive2) # rückgabe werte
html
<div class="form-check form-check-inline" id="field1">
<input class="form-check-input" type="radio" name="usb_device" value="option1" id="Check1" checked>
<label id="usb_device1" class="col-form-label col-md-4" for="Check1">{{usb_device1}}</label>
</div>
<div class="form-check form-check-inline" id="field2">
<input class="form-check-input" type="radio" name="usb_device" value="option2" id="Check2">
<label id="usb_device2" class="col-form-label col-md-4" for="Check2">{{usb_device2}}</label>
</div>
JavaScript
if ("usb_device1" == "")
{
document.getElementById("field1").hidden=true;
} else {
document.getElementById("field1").hidden=false;
}
if ("usb_device2" == "")
{
document.getElementById("field2").hidden=true;
} else {
document.getElementById("field2").hidden=false;
}
i tried different approaches within JavaScript like the one showed before or
document.getElementById("Check1").style.display = 'none'
but nothing worked so far.