E
E
Eugene2020-04-20 12:10:37
JavaScript
Eugene, 2020-04-20 12:10:37

The function saves the positions of only 9 checkboxes in cookies how to save the 10th checkbox in cookies?

<ul class="dropdown-menu dropup checkbox-menu allow-focus" aria-labelledby="dropdownMenu1" id="checks">  
  <li class="dropdown-header">Видимые поля</li>    
    <li >
      <label>
        <input id="CB1" type="checkbox" value="ON" checked> <?php echo lang('milestone'); ?>
      </label>
    </li>
  <li >
      <label>
        <input id="CB2" type="checkbox" value="ON" checked> <?php echo lang('assign_to'); ?>
      </label>
    </li>
  <li >
      <label>
        <input id="CB3" type="checkbox" value="ON" checked> <?php echo lang('collaborators'); ?>
      </label>
    </li>
    
  <li >
      <label>
        <input id="CB4" type="checkbox" value="ON" checked> <?php echo lang('description'); ?>
      </label>
    </li>
  <li >
      <label>
        <input id="CB5" type="checkbox" value="ON" checked> Вложения
      </label>
    </li>
  <li >
      <label>
        <input id="CB6" type="checkbox" value="ON" checked> <?php echo lang('status'); ?>
      </label>
    </li>
  <li >
      <label>
        <input id="CB7" type="checkbox" value="ON" checked> <?php echo lang('points'); ?>
      </label>
    </li>
  <li >
      <label>
        <input id="CB8" type="checkbox" value="ON" checked> Сроки
      </label>
    </li>
  <li >
      <label>
        <input id="CB9" type="checkbox" value="ON" checked> <?php echo lang('labels'); ?>
      </label>
    </li>
  <li >
      <label>
        <input id="CB10" type="checkbox" value="ON" checked> <?php echo lang('recurring'); ?>
      </label>
    </li>
  </ul>


var dcSplit, posnEq, firstGrp, lastGrp, posnCB, regEx, i = 0;
dcSplit = document.cookie.split("; ");
regEx = (/CB\d=/);
for (i = 0; i < dcSplit.length; i++) {
  posnEq = dcSplit[i].indexOf("=") + 1;
  posnCB = dcSplit[i].search(regEx);
  if (posnCB != -1) {
    firstGrp = dcSplit[i].substring(posnCB, posnEq - 1);
    lastGrp = dcSplit[i].substring(posnEq, dcSplit[i].length);
    document.getElementById(firstGrp).checked = eval(lastGrp);
  }
}
// ------
var now = new Date(),
  tomorrow, allInputs, cookieStr;
tomorrow = new Date((now.setDate(now.getDate()) + (1 * 24 * 60 * 60 * 1000))).toGMTString();
allInputs = document.getElementById("checks").getElementsByTagName("input");
for (i = 0; i < allInputs.length; i++) {
  allInputs[i].onclick = writeCookie;
}
// --------   
function writeCookie() {
  cookieStr = this.id + "=" + this.checked + "; expires=" + tomorrow + "; path=/";
  document.cookie = cookieStr;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Miit, 2020-04-20
@Miit

You have a check <instead of<=

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question