New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

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 · 6471 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

Are you sure you want to delete this note?

No

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.