Witam. Chciałbym stworzyć formularz z checkboxami, gdzie będzie można wybrać liczbę opcji z wcześniej podaną przez użytkownika i przekazaną w sesji. Znalazłem poniższy skrypt, który działa, ale tylko, gdy jest ustawiona stała liczba opcji, w tym przypadku 2. Czy istnieje możliwość by w kodzie javascriptu liczbę z sesji?
<script type="text/javascript">
function initCheckLimit
(elm
, count) { var cb = elm.getElementsByTagName('input');
for (var i = 0; i < cb.length; i++) {
if (cb[i].getAttribute('type') != 'checkbox') continue;
cb[i].onclick = function() {
var cn = this.parentNode.childNodes;
var checkCount = 0;
for (var j = 0; j < cn.length; j++) {
if (cn[j].nodeType != 1) continue;
if (cn[j].getAttribute('type') != 'checkbox') continue;
if (cn[j].checked) checkCount++;
if (checkCount > this._count) return false;
}
};
}
}
onload = function() {
initCheckLimit(document.getElementById('my_form'), 2);
};
</script>
<form id="my_form">
<div>
<input type="checkbox" />1
<input type="checkbox" />2
<input type="checkbox" />3
<input type="checkbox" />4
<input type="checkbox" />5
</div>
<div>
<input type="checkbox" />1
<input type="checkbox" />2
<input type="checkbox" />3
<input type="checkbox" />4
<input type="checkbox" />5
</div>
<div>
<input type="checkbox" />1
<input type="checkbox" />2
<input type="checkbox" />3
<input type="checkbox" />4
<input type="checkbox" />5
</div>
</form>