HTML5 and CSS3, Second Edition

(singke) #1
➤ {
➤ test:Modernizr.pattern&& Modernizr.required,
➤ nope:"javascripts/h5f.min.js",
➤ callback:function(url,result){
➤ if(!result){
➤ configureHSF();
➤ }
➤ }

]);

➤ }

Then, to activate H5F we write this code:


html5_validation/javascripts/fallbacks.js
varconfigureHSF=function(){
H5F.setup(document.getElementById("create_account"));
};

The load() function takes a string, an object, or an array of objects. We’re
passing two objects to Modernizr.load() now instead of one. To do that, we have
to place both objects in an array. That’s why the objects are wrapped in square
brackets.

We use document.getElementById() here because H5F needs a regular Document
Object Model element. If we used jQuery to fetch the element, we’d get a
jQuery object instead of the Element object and H5F wouldn’t know what to
do.

Client-side validation lets users see that they made mistakes, without waiting
for a server response or a page refresh. But remember that this feature could
be disabled or unavailable or simply incorrectly implemented, so you still
need to make sure you have a server-side strategy for validating data.

Form fields aren’t the only way to let users type data into a web page. Let’s
look at how we can let users enter text into regular HTML elements.

Chapter 3. Creating User-Friendly Web Forms • 58


Download from Wow! eBook <www.wowebook.com> report erratum • discuss

Free download pdf