Profile picture Schedule a Meeting
c a n d l a n d . n e t

Validate if checkbox is checked using really easy validation

Dusty Candland | |

/ Needs Really easy validation.js script & prototype.js /

function validateIfChecked(v, e) {
var cbId = e.getAttribute(‘usecheckbox’);
if (cbId != ‘undefined’) {
if ($(cbId).checked) {
var validationType = getValidationType(e);
return !Validation.get(‘IsEmpty’).test(v) && Validation.get(validationType).test(v)
}
else {
$(e).value = ‘’;
return true;
}
}
return true;
}

function getValidationType(e) {
var classes = e.className.split(‘ ’);
for (i = 0; i < classes.length; i++) {
if (classes[i].indexOf(‘validate-checkbox-’ >= 0))
return classes[i].replace(‘validate-checkbox-’, ‘’);
}
return ‘validate-number’; // default;
}

Validation.add(‘validate-checkbox-required’, ‘Please provide a valid value when checked’, validateIfChecked);
Validation.add(‘validate-checkbox-validate-number’, ‘Please provide a valid value when checked’, validateIfChecked);
Validation.add(‘validate-checkbox-validate-digits’, ‘Please provide a valid value when checked’, validateIfChecked);
Validation.add(‘validate-checkbox-validate-alpha’, ‘Please provide a valid value when checked’, validateIfChecked);
Validation.add(‘validate-checkbox-validate-alphanum’, ‘Please provide a valid value when checked’, validateIfChecked);
Validation.add(‘validate-checkbox-validate-date’, ‘Please provide a valid value when checked’, validateIfChecked);
Validation.add(‘validate-checkbox-validate-email’, ‘Please provide a valid value when checked’, validateIfChecked);
Validation.add(‘validate-checkbox-validate-url’, ‘Please provide a valid value when checked’, validateIfChecked);
Validation.add(‘validate-checkbox-validate-currency-dollar’, ‘Please provide a valid value when checked’, validateIfChecked);

Realy Easy Validation

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: