Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Integrating HTML5 form controls

From: Working with Data on the Web

Video: Integrating HTML5 form controls

HTML5 brought a lot of cool new toys to the table, but one area was especially welcome and needed and that's forms. There were numerous enhancements to form elements as part of the HTML5 specification, many of which have been implemented in modern browsers. In this lesson, we'll take a look at some of the most valuable changes and how you can best take advantage of them. I have open here the index.htm file from the chapter one 0103 folder of the exercise files.

Integrating HTML5 form controls

HTML5 brought a lot of cool new toys to the table, but one area was especially welcome and needed and that's forms. There were numerous enhancements to form elements as part of the HTML5 specification, many of which have been implemented in modern browsers. In this lesson, we'll take a look at some of the most valuable changes and how you can best take advantage of them. I have open here the index.htm file from the chapter one 0103 folder of the exercise files.

As you can see there's a pretty basic form here I'll scroll down just a bit more asking for info from potential students. We'll use this to illustrate the various HTML5 attributes and input types. I also have the same page open in my code editor, so we can take a peek under the hood from time to time. Now let's head back to the browser, and I'm going to refresh the page to simulate loading it for the first time, and you'll notice that when I do, the cursor jumps into the first field, ready for entry.

This occurs because the name field has an autofocus attribute. Let me show you that in the code. I'm going to scroll down to where my form starts on line 39, and here in the input field, you see as the second to last attribute autofocus. Now, you'll also notice the place holder text, your full name. Let's head back to the browser and watch what happens when I start typing. Instantly, the placeholder text disappears.

Again, that's controlled by an HTML5 attribute called, naturally placeholder. The text that appears is the placeholder's value, you see it as the attribute just before auto-focus. Now, if I change the placeholder value, lets make it Full name please, save the file and then head back to the browser, when it's refreshed, you see the new placeholder icon.

Both autofocus and placeholder are relatively well-supported in modern browsers. Support for the other attributes used in the name form field required that you see here is a little spottier but it's getting better. Watch what happens when I click submit without entering a name in the browser. We'll go back and just click submit I get a small pop-up asking me to fill out the field. Unfortunately, there's not a lot of controlled for the required validation. You really can't change the message.

And styling is pretty difficult as well. There are numerous other HTML5 attributes, but most don't have enough browser traction yet to be impactful. Lets turn our attention to the new HTML5 input types, there are a slew of new input types, 13 in all. Most of them apply to what are basically text input fields. I've got a number of examples in our form, first there's the email field. Now if we go back to the code and take a look at line 46 here.

You'll notice the type is set to email. In standard desktop browsers, you won't really see much in the way of change, but mobile browsers are a different animal altogether. Let's switch to an iPhone emulator, so you can see a real difference. Now, I have the page open in my emulator and I'm going to scroll down a little bit to where my form is. The form has not been optimized for responsive design, but it's close enough for government workers as my dad used to say. You'll get the idea. Now if I tap into the name field, there's a standard keyboard.

Now let me just enter my name. Click done, and let's go to the email field. The difference is subtle, but it's there. And now I have both an at symbol and a period available to me. Essential characters for any email address. Input types go a long way towards enhancing user experience. Now let me show you what I consider is a major ux enhancement. Let me just go ahead and click done here. And this time, I'll click into the cell phone field.

Now, I've got a numeric keyboard. Perfect for quickly entering phone numbers. This is because the field's input type is set to tel, t e l. As you can see the code on line 50. Now the enhancements aren't just restricted to different types of keyboards. Let's go into the birthday field, and now we have a very lovely date picker, so I can scroll down to something closer to my birthday, pretty quickly, let's see where I end up going. Good enough.

And in addition to an actual date picker, we have the range input type. Which you see here for the number of years for art study is set up as a slider. Now I don't have this set up to show the value chosen. That's one of the problems with the range input type, as implemented. You can overcome that by adding some JavaScript in, but for now, if you're using the standard range input type, you want to do so in situations where an exact value is not imperative, input types like date and range are still in development on the browser front, and you'll see a lot of different implementations of them.

For the time being, you need to rely on added JavaScript coding to make these HTML file form elements fully functional across the board. And if you need to implement range element right away. Check out my course, HTML5 Projects engaging e commerce.

Show transcript

This video is part of

Image for Working with Data on the Web
Working with Data on the Web

25 video lessons · 10153 viewers

Joseph Lowery
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Working with Data on the Web.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.