On my website I have a form, where useres can choose a filetype. I also included the checkbox "other", where the user can typein the desired file-extension. Via Flask I am creating a list, of all checked "filetype" checkboxes.
<label class="form-check">
<input class="form-check-input" type="checkbox" id="other" value=''>
<span class="form-check-label">Other
<input placeholder="e.g. 'msg'" name="filetype" onsubmit="save();" class="form-control input-lg" type="text" id="otherValue" value=>
</span>
</label> <!-- form-check -->
Here I have one big problem: with the Flask get-request: filetypeCheck = request.form.getlist('filetype')
I recieve all checked checkboxes plus the value of the form-control input-lg (even if "other" is not checked], which is most of the time empty. So the return of filetypeCheck is ['']. I only want the value of "otherValue" to be added to the "filetypeCheck"-list, if the checkbox "other" is checked otherwise filetypeCheck shoud be []. I have no clue how to continue... Thanks a lot for your help
some extra code:
<script type="text/javascript">
var otherCheckbox = document.querySelector('input[id="other"]');
var otherText = document.querySelector('input[id="otherValue"]');
otherText.style.visibility = 'hidden';
otherCheckbox.onchange = function(){
if(otherCheckbox.checked) {
otherText.style.visibility = 'visible';
//otherText.value = '';
} else {
otherText.style.visibility = 'hidden';
}
};
</script>
Aucun commentaire:
Enregistrer un commentaire