Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72473

Adding text-input of a html-form to Checkboxlist in Flask

$
0
0

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={{extension}}>
                </span>
</label> <!-- form-check -->

look like this

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>

I already tried the code below, but somehow I need to write the {{extension}} value also to the value of "other":

<label class="form-check" style="margin-bottom:0rem">
                                      <input class="form-check-input" name="filetype" type="checkbox" id="other" value='' onclick="save()">
                                      <span class="form-check-label" style="font-size:small">Other&nbsp; &nbsp;
                                          <input placeholder="e.g. 'msg'" onsubmit="save();" class="form-control input-lg" style="display:inline; font-size:small; height:30px; width:90px" type="text" id="otherValue" value={{extension}}>
                                      </span>
</label> <!-- form-check -->

Viewing all articles
Browse latest Browse all 72473

Trending Articles