Split Button Form Control

Posted by Jeremy Gillick on 15 Mar 2009 12:28 am in Code & Technical

A split button element is a submit button with a built-in menu of actions. My goal was to create a split button form control that is both semantic and accessible.

Stylized controls, like this, should only be used when there is a solid reason to do so. In general the default browser controls work fine and provide a pattern that users are familiar with. For certain situations, however, it is useful to provide a simple way to choose a single action using stylized controls.

Split Button HTML

<script type="text/javascript" src="splitbutton.js"></script> <p class="splitButton"> <select name="actions" id="actions" title="Choose Action"> <option>Send Message</option> <option>Flag</option> <option>Chug Pixie Stick</option> </select> <input type="submit" value="Go" /> </p>

This will create a split button with 3 options and the default button name will be “Choose Action” (see example above). The key elements here are:

  • A surrounding element with the splitButton class.
  • A select element with an optional title attribute.
  • A submit button.

If the select element has a title attribute, that text will be used as the default button name; otherwise, it will use the first (or selected) option as the button name.

When an action is selected the JavaScript will send a click event (via the click() function) to the submit button element in order submit the form.

The menu is also accessible with the keyboard. When you bring focus to control, the menu will open and you can use your arrows to select an option. Pressing ESC will close the menu.

Dependencies

This code uses YUI 2.6 with the Selector beta library and can easily be ported to jQuery or any other framework.

Download

Split button

Usage

You are free to download, modify and use this code anywhere you want. There are no restrictions.

4 Responses

  1. boardtc Says:

    March 30th, 2009 at 2:58 pm

    What’s the best way to email you? Was emailing about an extension re http://mozmonkey.com/about-jeremy.php
    and got:
    Hi. This is the qmail-send program at plesk-mail01.plus.net.
    I’m afraid I wasn’t able to deliver your message to the following addresses.
    This is a permanent error; I’ve given up. Sorry it didn’t work out.

    :
    Sorry, I wasn’t able to establish an SMTP connection. (#4.4.1)
    I’m not going to try again; this message has been in the queue too long.

  2. Lams Says:

    September 17th, 2009 at 11:50 pm

    Hi Jeremy,

    Can you upgrade your StockTicker firefox add-on to support Firefox 3.5 please? Please have a look the reviews in the add-on page - https://addons.mozilla.org/en-US/firefox/addon/183

  3. Thibault Says:

    November 5th, 2009 at 2:41 am

    Hello,

    I hope you are doing fine.

    My comment has nothing to do with your blog, I am a very pleased user of your firefox addon switch proxy.

    I have seen it is not compatible with FF 3.5, I am postponing my upgrade till your add on is available on it.

    That’s why I write this comment, to know if you are going to make your addon campatible with FF 3.5 or if you have switched to other subjects ?

    Anyway I have appreciated a lot using your addon

    Thanks a lot and Best regards

    Thibault

  4. hicagroonia Says:

    January 5th, 2010 at 7:51 am

    WaidgeWeite
    rd5d

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.