This tutorial was originally written when HTML 4.0 was in its infancy. HTML 4.01 is today’s standard specification for HTML and this tutorial has been updated to reflect the features of HTML 4.01. Editorial comments are shown contained in square braces — [ ]
First things first: Yonder we go again with a command that only certain browsers understand. Sorry, but it’s becoming a way of Internet life. You have to be running MSIE4.0 or better to get this effect. However, there is a way you can use JavaScript so that only MSIE browsers will display the code. I have a tutorial on it here. Of course you could also not worry about it too much. Browsers that don’t understand the commands will simply ignore them.
[All modern browsers in common use fully support HTML 4.01. Consequently, you can safely use these commands and expect them to be interpreted correctly. Of course, there may be an obscure, or less than commonly used browser that may have a problem with them, but the standard has been around for a while now, and you can’t really spend all your time trying to cater to those who don;t use modern browsers, can you?!!]
Okay, you’re going to like this one. Can you see up at the top of the browser window, on the left, you see File? See the little underline on the letter “F”? Do you know what that means? If not, don’t feel bad. I didn’t for the longest time until my mouse stopped working. A guy at a help desk actually explained it to me. That underline means that if you hold down the ALT key and hit “F”, that File menu will drop down. No kidding – try it.
The ALT key stands for “Alternative”. Holding that key sets an alternative function for whatever key is pressed. No, the CTRL key does not do the same thing. Control (CTRL) sets a separate function for the browser to perform. In fact, if you hold CTRL and press “F”, you’ll get the browser’s Find function. Cool. One key, three things.
To use this effect on your Web pages, you need to use at least one tag, ACCESSKEY, sometimes two, ACCESSKEY and LABEL. I’ll start by showing you the two together. It’ll be easier to get smaller rather than build later.
OK, take a look at the following three text boxes and TEXTAREA box. Notice how they each have a word in front and one of the word’s letters is underlined. Super. Without clicking on any of the boxes, hold down the ALT key (it has to be the alt key) and push one the underlined letters.
That was cool, huh? If you didn’t see it, look for the cursor to appear in the text box. You may also want to try typing something in the box, clicking off of the box and then using the ALT key to return. The cursor will appear at the end of the text. Very clever.
So what did it? Why, this did it now that you’ve asked:
FOR= sets the name what is to be labeled. I named this first text box Namebox. I could have named it superglue if I wanted, but I’m trying to keep things straight in my own head.
ACCESSKEY=set the key that will reacts with the ALT key to bring focus to the text box.
<U>N</U>ame: is basic HTML text that creates: Name.
/LABEL wraps it up.
OK, now we’re set with the label. Let’s apply it to a text box:
<INPUT TYPE=”TEXT” ID=”Namebox” SIZE=30>
The format should look very familiar to you by now. The only new attribute is that ID= deal. Notice it has the same name as the FOR=in the LABEL tag. That’s what links these two together.
That’s it. Now when the user clicks on ALT and “N”, he or she will jump their cursor to that text box denoted by “N”. Cool trick. And as you can see, it works with TEXTAREA boxes just as well.
Advertisement
What if the Letter’s Taken?
What’s that? The letter’s already taken? Evil Microsoft has dared to set up one of their menus using the same letter you want? How dare they!
It’s already happened. See how I have “E” set up to jump you to the Email text box? Notice at the top of your browser that “E” also should open the Edit menu. But it doesn’t. Your use of the Accesskey wins in the battle of the commands.
I guess that’s good in some ways, bad in others. I would suggest that unless it’s really required. Try to use letters that don’t pull down major menus. It’s just a suggestion.
LABEL and the Checkbox
This is fairly cool as well. You can use the LABEL command to get the checkboxes to check themselves. Try this. Click on the text, not the box.
There you go. Very smooth. The code is exactly the same as above, except you do not use an Accesskey and this is a checkbox. Come to think of it. It’s not just the same. It’s just close. (Sorry, I went into my Monty Python voice there). Here’s the code:
<FORM>
<LABEL FOR=”sendme”>Check to receive mailing</LABEL> <INPUT TYPE=”CHECKBOX” ID=”sendme” VALUE=”Send_me_stuff”>
</FORM>
Nothing to it. Now, the official word is that this will also work with radio buttons, and the send and reset buttons themselves. Well, that’s what the brochure says. I have found that yes, the tags to bring focus to the elements, but they do not trigger their function.
Here’s a radio button. I made it by simply changing the TYPE to radio. I also gave it new FOR= and ID= labels so that it wouldn’t interfere with the checkbox. Give it a shot. Click away.
See what I mean? Stick with what works. Radio buttons don’t play well with others.
Advertisement
Accesskey and Links
Just as LABEL with work without ACCESSKEY, ditto the other way around. When used inside of a hypertext link, the ACCESSKEY allows you to set that link to trigger through an ALT – somethinghot key. Here’s an example:
Wow! A variety of uses! None that spring directly to mind, but still a variety of uses.
Here’s the code that did the trick:
<A HREF=”page.html” ACCESSKEY=”A”> Press Alt-A for the example page.</A>
It’s a basic hypertext link that has the ACCESSKEY=”–” attribute stuck in there for good measure. Simple and efficient.
That’s That
There are still those DOS command loving people out there. I’m one of them. I started playing with computers when DOS was still a required thing to know. It has never left me. I still do a great amount of text manipulation though DOS command and prompts. Offering this on your pages will make people like me happy.
Unless, you mess up one of the menus along the top. Then you’ll make me mad.
Are you a game developer looking to jump into the futuristic world of virtual reality? If so, you will likely need to use VR game development platforms and tools to help you along the way, and here is a list of some of the best of the bunch to get you started. After reading this […]
While it is possible to create websites in the modern era using content management systems (CMS) like WordPress and website builder platforms like Shopify, it never hurts to learn the cornerstones of those web development tools, especially if you ever want to add your own custom functionality to your websites. What’s more, not every […]
The images in a web page make the page much more attractive, descriptive, and help improve user experience. In this web development tutorial, we will talk about how to work with images in HTML, and, specifically, background images, inline images, image insertion paths, and the most important attributes of the HTML tag. We will […]
Since the Internet first broke on to the scene in the late 80s and 90s, it has undergone a couple of significant changes, encapsulated by Web 1.0 and 2.0. Now, we are entering into the third version of the Web known as Semantic Web or Web 3.0. In this web development tutorial, we will explore […]
The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.
Advertiser Disclosure: Some of the products that appear on
this site are from companies from which TechnologyAdvice
receives compensation. This compensation may impact how and
where products appear on this site including, for example,
the order in which they appear. TechnologyAdvice does not
include all companies or all types of products available in
the marketplace.