02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

SelectBoxes aka ComboBoxes

Want to create a combobox in html? Gret. What Is it you ask? Comboboxs enables you to provide your users with a slectable list of options to pick from. For example: 'states' instead of the user needing to type the state.

Video Transcript

00:00Alrighty, so it's time for us to learn a new tag, and actually two new tags, and I think this is exciting.
00:05So, the next tag that we want to learn is basically a drop down, some call it a drop box.
00:12In HTML, it's called a selection box.
00:14Now, how do you create that selection box? It's very simple, and we'll see it immediately, and you'll see what I mean by that.
00:19You first start with the select tag.
00:22The select tag basically enables you to put a list of different options inside.
00:26Once you've created, the select tag will be created. It's going to be empty at first, but we'll have your little select tag, only nothing to select from.
00:33So, we're going to start now putting different selections inside of that select tag.
00:37The way we add different selections into our select tag is using the option, the option tag.
00:44Now, the option tag on the same concept basically, option, there we go.
00:50So, the option tag basically is not a self-enclosed, it's a full tag.
00:55It has a value and it has a label.
00:57So, for example, the label itself we'll put inside of the properties.
01:00For example, you're great.
01:06And let's do your five of those.
01:07You're great, you're okay, you're eh.
01:14It's also when you have a shopping thing and they want to know your date of birth.
01:20Yeah, you press on it and it shows the years.
01:23Absolutely, you blah and last but not least will be you suck.
01:34Okay, so we have here the list of the users could select and we know let's give it all to a label and let's do everything we did for previous columns.
01:42So, for our select group, we'll create a column here and we'll say here, what do you think of us?
01:49And this time it's not going to be for comments, we're going to go inside of our select.
01:53First of all, we're going to give it a name.
01:54The name itself is going to be R for rating and we'll give it an ID, we'll call it rate.
02:00And then we'll link them together with the rate, making sure that our label connects to our rating system.
02:05Okay, that's everything. We've done this already a few times before.
02:08Once I save this and we go back into our application and I find my application, we click on refresh,
02:14we'll see what do you think of us and our default value is you're great.
02:18But you could open it up and then select if you think you're okay, you're on your bar or you suck.
02:24Now, if you select you and you click on login, notice what happens when I send this information, the actual label that we put in is sent out.
02:33Now, because this element is so self enclosed, that's a lot of information to send the user to the server when it really we don't need so much information.
02:42What if we could only send one, two, three, four, five and have our server guy know what that means?
02:48There is a way to do it. Now, the way we do that is by going into our element and in our option itself,
02:54ignoring what we're actually showing the user, we put here a value and we set basically the value that we want it to actually be.
03:01So you're great equals five, like a five star system, you know, the five point five star.
03:07So we'll just create those options in all the different properties down here and we create five, four, three, two, one.
03:17Now, once we save that and we go back into our browser and click on refresh this time around, if I select, let's say you and I click on login,
03:26it's going to send the actual value in our URL to the server and it's not going to send the actual copy because we don't need to send the copy.
03:33That's just a waste of communications between the server and the client because it's information that we don't need to read out.
03:40We just need some sort of indicator, which a number is that indicator for us.
03:44Okay, that makes sense. Yes, sure. Beautiful.
03:47So we saw basically we saw basically our options.
03:50We saw we saw how to create a select and we saw how to create options.
03:54I want to talk about a couple of few more attributes.
03:56Let's start from the options. One other attribute.
03:58For example, what if we wanted to have a default value selected to do that?
04:03For example, maybe you're we want to be selected by default.
04:06So we'll put a space here and just type the word selected.
04:11Once we do that, it's going to automatically select option three as our default value.
04:15So we go back into our application and click on refresh.
04:18Your eye will be our default value that is selected.
04:22Okay. Yeah. And our battery of the mouse is low.
04:25So we should wrap it up quickly.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!