Skip to content
Advertisement

How can I save checkbox state to my database?

I’m trying to create a Todo-list app using (nodejs,ejs…) so for every todo I create a checkbox. If someone finishes his job and uses the button bin recycle to delete it, I save that using MongoDB but I’ve a problem when checking. When I reload the page this checked box disappears. In other words, my question is: How to save the information in my database if the checkbox is checked?

<div class="box">

  <% DoList.forEach(function(elem) { %>
    <div class="item">
      <input type="checkbox">
      <p class=i tems>
        <%=elem %>
      </p>
      <form action="/delete" method="post">
        <button class="delete" type="submit" name="delete" value='<%=elem%>'><img src="stylee/bin.png" alt="bin cycle"></button>
      </form>
    </div>

Advertisement

Answer

add your checkbox inside the form and add something like $yourcheckbox= isset($_POST[‘yourcheckboxname’])?1:0; 1 mean check 0 mean uncheck

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement