Halp
HTML
<form>
<input type="checkbox" id="someId">
<label for="someid">Some label</label>
<button type="submit">Submit</button>
</form>
<form>
<input type="checkbox" id="someOtherId">
<label for="someOtherId">Other label</label>
<input type="submit" value="Submit">
</form>
<form>
<input type="checkbox" id="andAnotherId">
<label for="andAnotherId">Another label</label>
<button type="submit">Submit</button>
</form>
JavaScript
var allForms = document.querySelectorAll('form');
for ( var i = 0, len = allForms.length; i < len; i++ ) {
allForms[i].style.color = "red"; //test
var agreementCheckbox = allForms[i].querySelectorAll('form input[type="checkbox"]');
var submitButton = allForms[i].querySelectorAll('form *[type="submit"]');
submitButton[0].disabled = true;
//agreementCheckbox[0].onchange = getCheckboxValue; //Works
//agreementCheckbox[0].onchange = getCheckboxValue(submitButton[0]); //Does not work :(
agreementCheckbox[0].onchange = handler(' world');
}
function handler(a){
return function (e){
alert('hello' + a);
}
}
function getCheckboxValue (submitButton) {
if ( this.checked ) {
alert ('Чекбокс включен');
} else {
alert ('Чекбокс выключен');
}
}