save checked checkboxes when Page reloads [duplicate]

自作多情 提交于 2019-12-24 22:25:29

问题


For my search-engine I designed a filter using a form with checkboxes. When submitting those, the filter function works fine (using Flask for this). Yet the checkboxes which where used as a filter are unchecked again when the results are shown. Do I need to save the information in the localStorage, and how can this be done? Thanks for your help <3

This is a part of my Code for the checkbox (I am a newbie to HTML/JS):

 <form>                  
  <article class="card-group-item">                      
    <header class="card-header">                          
      <span class="title">Document Types </span>               
    </header>                     
      <div class="filter-content">
          <div class="card-body">
             <label class="form-check" >
                 <input class="form-check-input" type="checkbox" name="doctype" value="offer" id="offer">
                 <span class="form-check-label">Offer</span>
             </label> <!-- form-check.// -->
             <button type="submit" class="btn btn-secondary btn-sm">Submit</button>
          </div> <!-- card-body.// -->
      </div>
   </article> <!-- card-group-item.// -->
 </form>

回答1:


Just add checked to it

<input class="form-check-input" type="checkbox" name="doctype" value="offer" id="offer" checked>



回答2:


Use checked in your checkbox and read here

 <form>                  
  <article class="card-group-item">                      
    <header class="card-header">                          
      <span class="title">Document Types </span>               
    </header>                     
      <div class="filter-content">
          <div class="card-body">
             <label class="form-check" >
                 <input class="form-check-input" type="checkbox" name="doctype" value="offer" id="offer" checked>
                 <span class="form-check-label">Offer</span>
             </label> <!-- form-check.// -->
             <button type="submit" class="btn btn-secondary btn-sm">Submit</button>
          </div> <!-- card-body.// -->
      </div>
   </article> <!-- card-group-item.// -->
 </form>


来源:https://stackoverflow.com/questions/58876694/save-checked-checkboxes-when-page-reloads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!