Client-side radio-button validation


XSP.getFieldValue = function getFieldValue(node) {
    if (node) {
        // Note, the node may have changed to a SPAN
        // if the edit box became read-only
        var type = (!node.type) ? null : node.type.toLowerCase();
        if (type == 'radio' || type == 'checkbox') {
            if (node.checked) {
                return node.value;
            }
            return '';
        } else if (type == 'fieldset') {
        	var els= node.getElementsByTagName('input');
        	for(var i= 0; i<els.length; i++) {
        		var el= els[i];
        		if (el.checked)
        			return el.value;
            }
            return '';
        } else if (node.multiple) {
            var sel = '';
            for (var i = 0; i < node.options.length; i++) {
                if (node.options[i].selected) {
                    if (sel) sel += ',';
                    sel += node.options[i].value;
                }
            }
            return sel;
        } else if (typeof node.value != 'undefined') {
            return node.value;
        }
    }
    return null;
};
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...