Return to Snippet

Revision: 47446
at June 8, 2011 05:13 by vagrantradio


Updated Code
// don't forget this
<script src="/jq/jquery.validate.js"></script>
<script>
jQuery(function() {
	if (!checkAttribute('input', 'required')) { // check for html5 validation
		jQuery("#form").validate(); // no? hey, use jQuery validate
	}

        if (!checkAttribute('input', 'autofocus')) { // check for html5 validation
                document.getElementById("q").focus(); // no? hey, use jQuery focus()
        }
});

function checkAttribute(element, attribute) { //the function
	var test = document.createElement(element);
	if (attribute in test) {
		return true;
	} else {
		return false;
	}
}	
</script>

Revision: 47445
at June 8, 2011 05:12 by vagrantradio


Initial Code
<!-- don't forget this -->
<script src="/jq/jquery.validate.js"></script>
<script>
jQuery(function() {
	if (!checkAttribute('input', 'required')) { // check for html5 validation
		jQuery("#form").validate(); // no? hey, use jQuery validate
	}

        if (!checkAttribute('input', 'autofocus')) { // check for html5 validation
                document.getElementById("q").focus(); // no? hey, use jQuery focus()
        }
});

function checkAttribute(element, attribute) { //the function
	var test = document.createElement(element);
	if (attribute in test) {
		return true;
	} else {
		return false;
	}
}	
</script>

Initial URL
http://diveintohtml5.org/forms.html

Initial Description
Couple of ways to check if HTML5 form elements exist and use a fallback if they don't.

Initial Title
HTML5 Form Validation w/ jQuery Fallbacks

Initial Tags
html5

Initial Language
jQuery