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

Including range form elements

From: HTML5 Projects: Engaging Ecommerce

Video: Including range form elements

The first step towards enhancing the user experience of our ecommerce catalog is to add in a form element new to HTML5, the range input type. It's a very straightforward tag with just a few attributes. In this lesson I'll also add in another form element, a basic text input type, so we can eventually display the actual range value as the slider moves. Finally, I'll show you a very cool CSS property that you don't want to implement to help with your slider stylings.

Including range form elements

The first step towards enhancing the user experience of our ecommerce catalog is to add in a form element new to HTML5, the range input type. It's a very straightforward tag with just a few attributes. In this lesson I'll also add in another form element, a basic text input type, so we can eventually display the actual range value as the slider moves. Finally, I'll show you a very cool CSS property that you don't want to implement to help with your slider stylings.

So here's what the page looks like at this current stage. You can see over on the right, under the Price Slider area, there is nothing there. So now let's switch over to our code editor. So I am going to scroll down to about line 67 here, where I have a little handy placeholder, insert range input type here. Let's delete that, and now I'll put in my code for the input tag, starting with input. I'm going to enter an id that we'll use later in our JavaScript routines, and let's just call this slider.

Next, we'll enter in the type for this input tag, and the type is going to be of course range. We want to enter in a number of different attributes now. Let's put in our minimum first. And I'm going to set the min to 50. We don't want to make our artwork too cheap. And we also made a maximum. So max, and let's make that 400 or too expensive. This is a school after all. Next, I'm going to put in an optional argument, step, so we can change how the range increments, and let's put in a step value of 25.

Finally, we want to put in our starting point, and that's handled through the value attribute. In some situations, as in the example I gave in an earlier chapter, you might want it to start right dead center, but in this situation, since what we're going to be doing is filtering out less expensive items, we want to show all of the items to start with. So we're going to place this value at its maximum, the upper limit, 400. Okay, let's close off the input tag. Now that's it for the slider, but as you saw in the previous chapter, there is an issue with the implementation of the slider where there is no real way to show what the range value is.

So let's put in another tag. This will be a simple text field, also an input tag, and this will have an id=rangeValue. That will again help us identify it for JavaScript routines a little further down the line. Next we'll set the type and set that to text. And I'm just going to put in a minimum size, and we'll make it size=2. And then let's close off the tag, and that's done.

So I'm going to save it. Let's head back to the browser for a second, refresh the page, and there is our basic slider and the accompanying text field. Let's bring in some styles to spice it up a bit. I already have the styles created, so all we need to do is to link them in. I am going to move up to the head section of the page, and we'll put this right after our link to the main.css file. So it's link href=, and we'll copy the path, CSS main. As you can see, the code hints begin to come up, so let's take advantage of that and we're going to go to range.css, and it's also going to be rel=stylesheet and we'll use the same media tags: screen and projection.

Okay, we close that tag, and I'll save the file. Now let me open up that particular CSS file, and you can see it has two rules in it: one that targets the input with a type of range and then the other one that goes a little bit further. That's actually targeting the thumb control that moves the sliders. Now most of the properties that you see here, from the second one in each entry on down, are pretty normal, and there is no reason to spend any time on them.

However, the very first entry in both rules, -webkit-appearance, deserves a little bit of explanation. This property allows you to specify a uniform look and feel for all your widgets. However, because we want a custom one, we actually need to set it to none. So let's go over to the browser and take a look. I'll refresh the page, and there is our revised browser. It's pretty, but if you move the control, you see that pretty is all it is.

However, we've got all of our basic elements in place to bring in the very first piece of functionality.

Show transcript

This video is part of

Image for HTML5 Projects: Engaging Ecommerce
HTML5 Projects: Engaging Ecommerce

13 video lessons · 6573 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 HTML5 Projects: Engaging Ecommerce.

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.